[unixODBC-dev] MS SQL unixODBC-2.2.8 freetds-0.62.3

lsunley at mb.sympatico.ca lsunley at mb.sympatico.ca
Wed Nov 10 23:32:00 GMT 2004


You did show the setup for the DSN freeTDS that you have
specified in your call to SQLConnect.

You also have to have your SQL server set up to use SQL server login
validation as well as "Windows NT" validation.


>	printf("About to SQLConnect()\n");
>	V_OD_erg = SQLConnect(V_OD_hdbc,
>				 (SQLCHAR*) "freeTDS", SQL_NTS,
>                                 (SQLCHAR*) "sa", SQL_NTS,
>                                 (SQLCHAR*) "", SQL_NTS);

Lorne

In <Pine.LNX.4.61.0411101555520.4859 at puppypad.co.za>, on 11/10/04 
   at 03:55 PM, Alf C Stockton <alf at stockton.co.za> said:


>I am attempting to attach my application, see attached, to a MS SQL
>database  running in Win2k using freeTDS as the driver. When my program
>gets to the  SQLConnect statement it achieves the following error/s

>About to SQLConnect()
>Error SQLConnect -1
>[unixODBC][Driver Manager]Data source name not found, and no default
>driver  specified (0)

>tsql -SDogHouse -Usa
>achieves
>locale is "C"
>locale charset is "ANSI_X3.4-1968"
>Password:
>Msg 18452, Level 14, State 1, Server , Line 0
>Login failed for user 'sa'. Reason: Not associated with a trusted SQL
>Server  connection.
>Msg 20014, Level 9, State 0, Server OpenClient, Line 0
>Login incorrect.
>There was a problem connecting to the server

>The sa user has no/blank password.

>nmap -sS DogHouse

>Starting nmap 3.50 ( http://www.insecure.org/nmap/ ) at 2004-11-10 15:49
>UTC Interesting ports on DogHouse (192.168.1.3):
>(The 1654 ports scanned but not shown below are in state: closed) PORT    
>STATE SERVICE
>135/tcp  open  msrpc
>139/tcp  open  netbios-ssn
>445/tcp  open  microsoft-ds
>1025/tcp open  NFS-or-IIS
>1433/tcp open  ms-sql-s

>Nmap run completed -- 1 IP address (1 host up) scanned in 0.689 seconds

>This shows that the port 1433 is open.

>Please tell me what I am missing.

>---

>Regards,
>Alf Stockton	www.stockton.co.za

>A billion here, a couple of billion there -- first thing you know it adds
>up to be real money.
>  		-- Senator Everett McKinley Dirksen

>/* odbc.c
> *
> * Compile with gcc odbc.c -o odbc -lodbc
> *
> *   testing unixODBC
> */
>#include <stdlib.h>
>#include <stdio.h>
>#include <sql.h>
>#include <sqlext.h>
>#include <sqltypes.h>

>SQLHENV			V_OD_Env;     // Handle ODBC environment
>long			V_OD_erg;     // result of functions
>SQLHDBC			V_OD_hdbc;    // Handle connection

>char			V_OD_stat[10]; // Status SQL
>SQLINTEGER		V_OD_err,V_OD_rowanz,V_OD_id;
>SQLSMALLINT		V_OD_mlen;
>char			V_OD_msg[200],V_OD_buffer[200];
>// Added by Alf
>SQLHSTMT 		V_OD_hstmt;   // Handle for a statement
>SQLINTEGER 		V_OD_err,V_OD_id;
>char 			V_OD_buffer[200];
>SQLSMALLINT      	V_OD_colanz;    // Num of columns
>// end of Alf's add.
>const char servername[] = "192.168.1.3";
>char 			tmp[256];
>int 			res, len;

>int main(int argc,char *argv[])
>{
>	// 1. allocate Environment handle and register version 
>//	printf("About to SQLAllocHandle()\n");
>	V_OD_erg=SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&V_OD_Env);
>	if ((V_OD_erg != SQL_SUCCESS) && (V_OD_erg != SQL_SUCCESS_WITH_INFO))
>	{
>		printf("Error AllocHandle\n");
>		exit(0);
>	}
>//	printf("About to SQLSetEnvAttr()\n");
>	V_OD_erg=SQLSetEnvAttr(V_OD_Env, SQL_ATTR_ODBC_VERSION, 
>                               (void*)SQL_OV_ODBC3, 0); 
>	if ((V_OD_erg != SQL_SUCCESS) && (V_OD_erg != SQL_SUCCESS_WITH_INFO))
>	{
>		printf("Error SetEnv\n");
>		SQLFreeHandle(SQL_HANDLE_ENV, V_OD_Env);
>		exit(0);
>	}
>	// 2. allocate connection handle, set timeout
>//	printf("About to SQLAllocHandle()\n");
>	V_OD_erg = SQLAllocHandle(SQL_HANDLE_DBC, V_OD_Env, &V_OD_hdbc); 
>	if ((V_OD_erg != SQL_SUCCESS) && (V_OD_erg != SQL_SUCCESS_WITH_INFO))
>	{
>		printf("Error AllocHDB %d\n",V_OD_erg);
>		SQLFreeHandle(SQL_HANDLE_ENV, V_OD_Env);
>		exit(0);
>	}
>//	printf("About to SQLSetConnectAttr()\n"); 	
>	SQLSetConnectAttr(V_OD_hdbc, SQL_LOGIN_TIMEOUT, (SQLPOINTER *)5, 0);
>	// 3. Connect to the datasource "web"

>	printf("About to SQLConnect()\n");
>	V_OD_erg = SQLConnect(V_OD_hdbc,
>				 (SQLCHAR*) "freeTDS", SQL_NTS,
>                                 (SQLCHAR*) "sa", SQL_NTS,
>                                 (SQLCHAR*) "", SQL_NTS);
>	if ((V_OD_erg != SQL_SUCCESS) && (V_OD_erg != SQL_SUCCESS_WITH_INFO))
>	{
>		printf("Error SQLConnect %d\n",V_OD_erg);
>		SQLGetDiagRec(SQL_HANDLE_DBC, V_OD_hdbc,1, 
>		              V_OD_stat, &V_OD_err,V_OD_msg,100,&V_OD_mlen);
>		printf("%s (%d)\n",V_OD_msg,V_OD_err);
>		SQLFreeHandle(SQL_HANDLE_ENV, V_OD_Env);
>		exit(0);
>	}

>	printf("Connected !\n");
>	V_OD_erg=SQLExecDirect(V_OD_hstmt,
>             "SELECT mac_name, a_date, a_time, amnt, message_descr FROM
>jack2 WHERE message_id = 34 order by a_date desc, a_time desc",SQL_NTS);
> 	if ((V_OD_erg != SQL_SUCCESS) && (V_OD_erg != SQL_SUCCESS_WITH_INFO))
>    		{
>     		printf("Error Select %d\n",V_OD_erg);
>     		SQLGetDiagRec(SQL_HANDLE_DBC, V_OD_hdbc,1, V_OD_stat, &V_OD_err,
>                	       V_OD_msg,100,&V_OD_mlen);
>     		printf("%s (%d)\n",V_OD_msg,V_OD_err);
>     		SQLFreeHandle(SQL_HANDLE_DBC,V_OD_hdbc);
>     		SQLFreeHandle(SQL_HANDLE_STMT,V_OD_hstmt);
>     		SQLFreeHandle(SQL_HANDLE_ENV, V_OD_Env);
>		exit(0);
>    		}

>	SQLDisconnect(V_OD_hdbc);
>	SQLFreeHandle(SQL_HANDLE_ENV, V_OD_Env);
>	/* continued on next page */
>}

>--8323328-1849124065-1100098217=:4571
>Content-Type: TEXT/PLAIN; CHARSET=US-ASCII; NAME="odbc.c"
>Content-Transfer-Encoding: BASE64
>Content-Description: 
>Content-Disposition: ATTACHMENT; FILENAME="odbc.c"

>_______________________________________________
>unixODBC-dev mailing list
>unixODBC-dev at easysoft.com
>http://mail.easysoft.com/mailman/listinfo/unixodbc-dev


-- 
-----------------------------------------------------------
lsunley at mb.sympatico.ca
-----------------------------------------------------------




More information about the unixODBC-dev mailing list