none
Service which connect to sql server using sql native client failed in windows server 2008 RRS feed

  • Question

  • Environment:  OS:Window Server 2008

                         Database: SQL Server 2005

     

    I write a windows service(automatic starts up when OS starts.) which will connect to SQL Server when starts up.

     

    The connection code simply like the following:

     

     retcode = SQLDriverConnect( hdbc,  NULL, (UCHAR *) "DSN=test;UID=test;PWD=test;APP=...",
                                    (SQLSMALLINT) strlen("DSN=test;UID=test;PWD=test;APP=..."),  (UCHAR *) OutConnStr, 

                                     (SQLSMALLINT) sizeof(OutConnStr),  &OutConnStrLen, SQL_DRIVER_NOPROMPT);

     

     

    (1) If i config the DSN using the "SQL Server" as the driver, the service will connect to the database successfully during the starting process when the OS start up. Everything is OK.

     

    (2) If i config the DSN using the "SQL Native Client" as the driver, the service will fail to connect to the database during the starting process when the OS start up. But if i start up the service again(start up it in services manager), it will connect to the database successfully.

    That is to say, the connection to the database only failed at its first start just when the OS restart.

     

    How can i make my service connect to the database successfully at the first start up when using SQL Native Client?

     

    Thanks in advance!

    Monday, October 27, 2008 8:34 AM

Answers