pulse
Goto Top

Keine Verbindung mit MS SQL-Server-2005

Keine Verbindung mit der Datenbank von meinem Programm aus

Hallo Administrator-Gemeinde...

Momentan stehe ich vor einem recht hartnäckigen Problem...
ich schreibe momentan an einem DatenBank-Update-Service...
und dort muss ich 2 Datenbanken updaten...
problem dabei macht die verbindung zum MS SQL-Server 2005
den wir hier in der Firma haben.

Und zwar handelt es sich um ein C++-Programm
Hier erstmal die Funktion, die den Datenbank-Zugriff öffnen soll(schließen ist momentan auch noch dabei)

int cl_event::sql_open()
{


SQLHENV henv;
SQLHDBC hdbc;
SQLHSTMT hstmt;
SQLRETURN retcode;
SQLPOINTER rgbValue;
int i = 5;
rgbValue = &i;

SQLCHAR InConnStr[255]="Driver=(SQL Native Client);Server=BASE-1;Database=TESTDB;Trusted_Connection=yes;Network=dbnmpntw;";  


SQLWCHAR OutConnStr[255];
SQLSMALLINT OutConnStrLen; 

// Allocate environment handle
retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);



// Set the ODBC version environment attribute
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {

retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER*)SQL_OV_ODBC3, 0); 

	// Allocate connection handle
	if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {

	retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc); 

		// Set login timeout to 5 seconds
		if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {

		SQLSetConnectAttr(hdbc, SQL_LOGIN_TIMEOUT, (SQLPOINTER)(rgbValue), 0);

retcode = SQLDriverConnect( // SQL_NULL_HDBC
hdbc,
NULL,
(SQLWCHAR*)InConnStr,
_countof(InConnStr),
OutConnStr,
sizeof(OutConnStr),
&OutConnStrLen,
SQL_DRIVER_NOPROMPT ); 



		// Allocate statement handle
		if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {  

		retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt); 

		// Process data
		if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {

		SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
               }
               SQLDisconnect(hdbc);
            }
            SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
         }
      }
      SQLFreeHandle(SQL_HANDLE_ENV, henv);
}
return 0;
}

und zwar bekomme ich nach dem SQLDriverConnect eine -1 zurück..also einen SQL-Error....sprich...keine Verbindung...
Hat jemand eine idee woran das liegen kann?
Die Berechtigungen für den Zugriff auf die DB habe ich, laut eines Mitarbeiters...


Bin für schnelle und gute Hilfe wirklich dankbar...kau schon 2 Tage an diesem Problem rum... =(


Chris

Content-Key: 68077

Url: https://administrator.de/contentid/68077

Ausgedruckt am: 29.03.2024 um 05:03 Uhr

Mitglied: pulse
pulse 22.02.2008 um 16:20:49 Uhr
Goto Top
Problem gelöst, durch Nutzung der SQL-Komponente der .NET-Framework