<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[SQL Connect mit Winapi funkz nicht]]></title><description><![CDATA[<p>hi<br />
ich will eine sql verbindung mit einem entfernten (aber lokalem LAN) MS SQL Server aufnehmen</p>
<p>der entfernte Computername ist &quot;SERVER&quot;<br />
der SQL Instanz Name ist &quot;test&quot;<br />
user ist &quot;sa&quot; - kein pass</p>
<p>ich habe im Internet <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcconnecting_with_sqlconnect.asp" rel="nofollow">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcconnecting_with_sqlconnect.asp</a> und <a href="http://www.willemer.de/informatik/db/odbcapi.htm" rel="nofollow">http://www.willemer.de/informatik/db/odbcapi.htm</a>)einen Beispiel code gefunden, der zu einer Datenbank verbinden soll.<br />
Aber es klappt nicht.</p>
<p>als retCode bei sqlconnect kriege ich immer einen Fehler von 0xCCCC zurück.<br />
Dabei komme ich in MSDEV 2003 über den Datenbank Explorer auf die Datenbank ohne Probleme.</p>
<p>Was mache ich falsch???</p>
<p>THX</p>
<pre><code class="language-cpp">// sqlconsoletest.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
//

#include &quot;stdafx.h&quot;
#include &quot;windows.h&quot;
#include &lt;sql.h&gt;
#include &lt;sqlext.h&gt;

#define MYSQLSUCCESS(rc) ((rc==SQL_SUCCESS)||(rc==SQL_SUCCESS_WITH_INFO))
HSTMT hstmt;
HENV hEnv;
HDBC hDBC;
SQLRETURN retCode;

unsigned char szData[1000];  

void error_out(void)
{
   unsigned char szSQLSTATE[10];
   SDWORD nErr;
   unsigned char msg[SQL_MAX_MESSAGE_LENGTH+1];
   SWORD cbmsg;

   while(SQLError(0,0,hstmt,szSQLSTATE,&amp;nErr,msg,sizeof(msg),&amp;cbmsg)==
   SQL_SUCCESS)
   {
      wsprintf((char *)szData,&quot;Error:\nSQLSTATE=%s,Native  error=%ld,msg='%s'&quot;,
         szSQLSTATE,nErr,msg);
      MessageBox(NULL,(const char *)szData,&quot;ODBC Error&quot;,MB_OK);

   }

}

int _tmain(int argc, _TCHAR* argv[])
{

	SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &amp;hEnv);  
	SQLSetEnvAttr(hEnv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, SQL_IS_INTEGER);
	SQLAllocHandle(SQL_HANDLE_DBC, hEnv, &amp;hDBC);
	if (hDBC) {
//**************** hier FEHLER *************************

		retCode = SQLConnect(hDBC, (UCHAR *)&quot;SERVER\\test&quot;, SQL_NTS, 
							(UCHAR *)&quot;sa&quot;,SQL_NTS,(UCHAR *)&quot;&quot;,0);

		//SQLAllocStmt(hDBC,&amp;hstmt);
		// Deallocate handles, display error message, and exit.
		if (!MYSQLSUCCESS(retCode))
		{
			SQLFreeEnv(hEnv);
			SQLFreeConnect(hDBC);
			error_out();
			exit(-1);
		}

		HSTMT hStmt;
		RETCODE retCode;
		char strPerformer[1024];
		char strTitle[1024];
		long len;

			retCode = SQLAllocHandle(SQL_HANDLE_STMT, hDBC, &amp;hStmt);
			if (retCode==SQL_SUCCESS || retCode==SQL_SUCCESS_WITH_INFO) {
retCode = SQLExecDirect(hStmt, (UCHAR*)&quot;SELECT * FROM roVNC&quot;, SQL_NTS);
				if (retCode==SQL_SUCCESS || retCode==SQL_SUCCESS_WITH_INFO) {
					SQLBindCol(hStmt, 1, SQL_C_CHAR, strPerformer, 1024, &amp;len);
					SQLBindCol(hStmt, 2, SQL_C_CHAR, strTitle, 1024, &amp;len);
					while (1) {
						retCode = SQLFetch(hStmt);
						if (retCode==SQL_SUCCESS || retCode==SQL_SUCCESS_WITH_INFO) {
							MessageBox(0, strTitle, strPerformer, MB_OK);
						}else {
							break;
						}
					}
				} else {
					MessageBox(0,&quot;ExecDirect failed&quot;, &quot;bad&quot;, MB_OK);
				}
				SQLFreeHandle(SQL_HANDLE_STMT, hStmt);
			}else{
				MessageBox(0,&quot;Statement failed&quot;, &quot;bad&quot;, MB_OK);
			}

		SQLDisconnect(hDBC);
		SQLFreeHandle(SQL_HANDLE_DBC, hDBC);
	}
	SQLFreeHandle(SQL_HANDLE_ENV, hEnv);

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/98130/sql-connect-mit-winapi-funkz-nicht</link><generator>RSS for Node</generator><lastBuildDate>Mon, 27 Apr 2026 16:36:01 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/98130.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 16 Jan 2005 21:08:44 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to SQL Connect mit Winapi funkz nicht on Sun, 16 Jan 2005 21:11:19 GMT]]></title><description><![CDATA[<p>hi<br />
ich will eine sql verbindung mit einem entfernten (aber lokalem LAN) MS SQL Server aufnehmen</p>
<p>der entfernte Computername ist &quot;SERVER&quot;<br />
der SQL Instanz Name ist &quot;test&quot;<br />
user ist &quot;sa&quot; - kein pass</p>
<p>ich habe im Internet <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcconnecting_with_sqlconnect.asp" rel="nofollow">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcconnecting_with_sqlconnect.asp</a> und <a href="http://www.willemer.de/informatik/db/odbcapi.htm" rel="nofollow">http://www.willemer.de/informatik/db/odbcapi.htm</a>)einen Beispiel code gefunden, der zu einer Datenbank verbinden soll.<br />
Aber es klappt nicht.</p>
<p>als retCode bei sqlconnect kriege ich immer einen Fehler von 0xCCCC zurück.<br />
Dabei komme ich in MSDEV 2003 über den Datenbank Explorer auf die Datenbank ohne Probleme.</p>
<p>Was mache ich falsch???</p>
<p>THX</p>
<pre><code class="language-cpp">// sqlconsoletest.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
//

#include &quot;stdafx.h&quot;
#include &quot;windows.h&quot;
#include &lt;sql.h&gt;
#include &lt;sqlext.h&gt;

#define MYSQLSUCCESS(rc) ((rc==SQL_SUCCESS)||(rc==SQL_SUCCESS_WITH_INFO))
HSTMT hstmt;
HENV hEnv;
HDBC hDBC;
SQLRETURN retCode;

unsigned char szData[1000];  

void error_out(void)
{
   unsigned char szSQLSTATE[10];
   SDWORD nErr;
   unsigned char msg[SQL_MAX_MESSAGE_LENGTH+1];
   SWORD cbmsg;

   while(SQLError(0,0,hstmt,szSQLSTATE,&amp;nErr,msg,sizeof(msg),&amp;cbmsg)==
   SQL_SUCCESS)
   {
      wsprintf((char *)szData,&quot;Error:\nSQLSTATE=%s,Native  error=%ld,msg='%s'&quot;,
         szSQLSTATE,nErr,msg);
      MessageBox(NULL,(const char *)szData,&quot;ODBC Error&quot;,MB_OK);

   }

}

int _tmain(int argc, _TCHAR* argv[])
{

	SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &amp;hEnv);  
	SQLSetEnvAttr(hEnv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, SQL_IS_INTEGER);
	SQLAllocHandle(SQL_HANDLE_DBC, hEnv, &amp;hDBC);
	if (hDBC) {
//**************** hier FEHLER *************************

		retCode = SQLConnect(hDBC, (UCHAR *)&quot;SERVER\\test&quot;, SQL_NTS, 
							(UCHAR *)&quot;sa&quot;,SQL_NTS,(UCHAR *)&quot;&quot;,0);

		//SQLAllocStmt(hDBC,&amp;hstmt);
		// Deallocate handles, display error message, and exit.
		if (!MYSQLSUCCESS(retCode))
		{
			SQLFreeEnv(hEnv);
			SQLFreeConnect(hDBC);
			error_out();
			exit(-1);
		}

		HSTMT hStmt;
		RETCODE retCode;
		char strPerformer[1024];
		char strTitle[1024];
		long len;

			retCode = SQLAllocHandle(SQL_HANDLE_STMT, hDBC, &amp;hStmt);
			if (retCode==SQL_SUCCESS || retCode==SQL_SUCCESS_WITH_INFO) {
retCode = SQLExecDirect(hStmt, (UCHAR*)&quot;SELECT * FROM roVNC&quot;, SQL_NTS);
				if (retCode==SQL_SUCCESS || retCode==SQL_SUCCESS_WITH_INFO) {
					SQLBindCol(hStmt, 1, SQL_C_CHAR, strPerformer, 1024, &amp;len);
					SQLBindCol(hStmt, 2, SQL_C_CHAR, strTitle, 1024, &amp;len);
					while (1) {
						retCode = SQLFetch(hStmt);
						if (retCode==SQL_SUCCESS || retCode==SQL_SUCCESS_WITH_INFO) {
							MessageBox(0, strTitle, strPerformer, MB_OK);
						}else {
							break;
						}
					}
				} else {
					MessageBox(0,&quot;ExecDirect failed&quot;, &quot;bad&quot;, MB_OK);
				}
				SQLFreeHandle(SQL_HANDLE_STMT, hStmt);
			}else{
				MessageBox(0,&quot;Statement failed&quot;, &quot;bad&quot;, MB_OK);
			}

		SQLDisconnect(hDBC);
		SQLFreeHandle(SQL_HANDLE_DBC, hDBC);
	}
	SQLFreeHandle(SQL_HANDLE_ENV, hEnv);

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/698343</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/698343</guid><dc:creator><![CDATA[Dezipaitor]]></dc:creator><pubDate>Sun, 16 Jan 2005 21:11:19 GMT</pubDate></item><item><title><![CDATA[Reply to SQL Connect mit Winapi funkz nicht on Sun, 16 Jan 2005 21:47:50 GMT]]></title><description><![CDATA[<p>benutze nun diesen code:<br />
und kriege als Fehler:</p>
<blockquote>
<p>[Microsoft][ODBC Driver Manager] Der Datenquellenname wurde nicht gefunden, und<br />
es wurde kein Standardtreiber angegeben</p>
</blockquote>
<pre><code class="language-cpp">int _tmain(int argc, _TCHAR* argv[])
{
   HENV   hEnv = NULL; // Env Handle from SQLAllocEnv()
   HDBC   hDBC = NULL; // Connection handle
   HSTMT  hStmt = NULL;// Statement handle
   UCHAR  szDSN[SQL_MAX_DSN_LENGTH] = &quot;SERVER\\test&quot;;// Data Source Name buffer
   UCHAR  szUID[10] = &quot;test&quot;;// User ID buffer
   UCHAR  szPasswd[10] = &quot;test&quot;;// Password buffer
   UCHAR  szModel[128];// Model buffer
   SDWORD cbModel;// Model buffer bytes recieved
   char   buff[9] = &quot;Testing&quot;;
   UCHAR  szSqlStr[128]= &quot;INSERT into (Tablename) (ColumnName) Values ('Testing')&quot; ;

   RETCODE retcode;

  //sprintf((char*)szSqlStr,&quot;INSERT into (Tablename)(Columname) Values ('%s')&quot;,buff);
  // Allocate memory for ODBC Environment handle
  SQLAllocEnv (&amp;hEnv);

  // Allocate memory for the connection handle
  SQLAllocConnect (hEnv, &amp;hDBC);

  // Connect to the data source &quot;test&quot; using userid and password.
  retcode = SQLConnect (hDBC, szDSN, SQL_NTS, szUID, SQL_NTS, szPasswd, SQL_NTS);

#define MSG_LEN 256 /* error message buffer length */
UCHAR sqlState[6]; /* buffer to store SQLSTATE */
SDWORD nativeErr; /* native error code */
UCHAR errMsg[MSG_LEN]; /* buffer to store error message */
SWORD realMsgLen; /**/

retcode = SQLError(hEnv, hDBC, hStmt, sqlState,
		&amp;nativeErr, errMsg, MSG_LEN, &amp;realMsgLen);
	printf((char*)errMsg);

  if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
  {
      // Allocate memory for the statement handle
      retcode = SQLAllocStmt (hDBC, &amp;hStmt);  

      // Prepare the SQL statement by assigning it to the statement handle
      retcode = SQLPrepare (hStmt, szSqlStr, sizeof (szSqlStr)); 

      // Execute the SQL statement handle
      retcode = SQLExecute (hStmt);    

      // Project only column 1 which is the models
      SQLBindCol (hStmt, 1, SQL_C_CHAR, szModel, sizeof(szModel), &amp;cbModel);

      // Get row of data from the result set defined above in the statement
      retcode = SQLFetch (hStmt);

      // Free the allocated statement handle
      SQLFreeStmt (hStmt, SQL_DROP);

      // Disconnect from datasource
      SQLDisconnect (hDBC);
  }    

  // Free the allocated connection handle
  SQLFreeConnect (hDBC);  

  // Free the allocated ODBC environment handle
  SQLFreeEnv (hEnv);

  return 0;
}

/*	SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &amp;hEnv);  
	SQLSetEnvAttr(hEnv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, SQL_IS_INTEGER);
	SQLAllocHandle(SQL_HANDLE_DBC, hEnv, &amp;hDBC);
	if (hDBC) {
		retCode = SQLConnect(hDBC, (UCHAR *)&quot;DYNGATESERVER\\roxtra&quot;, SQL_NTS, 
							(UCHAR *)&quot;sa&quot;,SQL_NTS,(UCHAR *)&quot;&quot;,0);

		int i = GetLastError();

		//SQLAllocStmt(hDBC,&amp;hstmt);
		// Deallocate handles, display error message, and exit.
		if (!MYSQLSUCCESS(retCode))
		{
			SQLFreeEnv(hEnv);
			SQLFreeConnect(hDBC);
			error_out();
			exit(-1);
		}

		HSTMT hStmt;
		RETCODE retCode;
		char strPerformer[1024];
		char strTitle[1024];
		long len;

			retCode = SQLAllocHandle(SQL_HANDLE_STMT, hDBC, &amp;hStmt);
			if (retCode==SQL_SUCCESS || retCode==SQL_SUCCESS_WITH_INFO) {
				retCode = SQLExecDirect(hStmt, (UCHAR*)&quot;SELECT * FROM roVNC&quot;, SQL_NTS);
				if (retCode==SQL_SUCCESS || retCode==SQL_SUCCESS_WITH_INFO) {
					SQLBindCol(hStmt, 1, SQL_C_CHAR, strPerformer, 1024, &amp;len);
					SQLBindCol(hStmt, 2, SQL_C_CHAR, strTitle, 1024, &amp;len);
					while (1) {
						retCode = SQLFetch(hStmt);
						if (retCode==SQL_SUCCESS || retCode==SQL_SUCCESS_WITH_INFO) {
							MessageBox(0, strTitle, strPerformer, MB_OK);
						}else {
							break;
						}
					}
				} else {
					MessageBox(0,&quot;ExecDirect failed&quot;, &quot;bad&quot;, MB_OK);
				}
				SQLFreeHandle(SQL_HANDLE_STMT, hStmt);
			}else{
				MessageBox(0,&quot;Statement failed&quot;, &quot;bad&quot;, MB_OK);
			}

		SQLDisconnect(hDBC);
		SQLFreeHandle(SQL_HANDLE_DBC, hDBC);
	}
	SQLFreeHandle(SQL_HANDLE_ENV, hEnv);

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/698364</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/698364</guid><dc:creator><![CDATA[Dezipaitor]]></dc:creator><pubDate>Sun, 16 Jan 2005 21:47:50 GMT</pubDate></item><item><title><![CDATA[Reply to SQL Connect mit Winapi funkz nicht on Mon, 17 Jan 2005 21:24:58 GMT]]></title><description><![CDATA[<p>Also es geht, wenn ich einen DSN Eintrag anlege, über die ODBC Verwaltung.</p>
<p>Aber warum muss ich das überhaupt machen? Andere Anwendungen (DBmgrK und MSDEV .NET) können es auch ohne!</p>
<p>Über .NET mache ich einfach folgendes:</p>
<pre><code class="language-cpp">sqlConn=new SqlConnection();

sqlConn.ConnectionString= &quot;User ID=test; Password=test; Initial Catalog=test; Data Source=testserer\testSQL&quot;;

sqlConn.Open();
if (sqlConn.State != System.Data.ConnectionState.Open)
return false;
</code></pre>
<p>Funktioniert Wunderbar.</p>
<p>Jetzt nur noch mit der Winapi?!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/698954</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/698954</guid><dc:creator><![CDATA[Dezipaitor]]></dc:creator><pubDate>Mon, 17 Jan 2005 21:24:58 GMT</pubDate></item></channel></rss>