<?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-Verbindung aufbauen (c++)]]></title><description><![CDATA[<p>Servus...</p>
<p>Also ich versuche momentan eine SQL-Verbindung aufzubauen...aber irgendwie find ich nicht wirklich was gescheites...da ich mich da auch überhaupt gar nicht mit auskenne...</p>
<p>Welche includes, und vielleicht beispiele wären sehr hilfreich... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title="=("
      alt="😞"
    /></p>
<p>Schonmal danke im vorraus..</p>
<p>der chris</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/191558/sql-verbindung-aufbauen-c</link><generator>RSS for Node</generator><lastBuildDate>Wed, 01 Jul 2026 08:19:42 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/191558.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 04 Sep 2007 11:19:47 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to SQL-Verbindung aufbauen (c++) on Tue, 04 Sep 2007 11:19:47 GMT]]></title><description><![CDATA[<p>Servus...</p>
<p>Also ich versuche momentan eine SQL-Verbindung aufzubauen...aber irgendwie find ich nicht wirklich was gescheites...da ich mich da auch überhaupt gar nicht mit auskenne...</p>
<p>Welche includes, und vielleicht beispiele wären sehr hilfreich... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title="=("
      alt="😞"
    /></p>
<p>Schonmal danke im vorraus..</p>
<p>der chris</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1358661</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1358661</guid><dc:creator><![CDATA[legion]]></dc:creator><pubDate>Tue, 04 Sep 2007 11:19:47 GMT</pubDate></item><item><title><![CDATA[Reply to SQL-Verbindung aufbauen (c++) on Tue, 04 Sep 2007 11:20:43 GMT]]></title><description><![CDATA[<p>Was soll eine SQL-Verbindung sein? SQL ist eine Sprache.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1358663</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1358663</guid><dc:creator><![CDATA[hmmmmmmmmmm]]></dc:creator><pubDate>Tue, 04 Sep 2007 11:20:43 GMT</pubDate></item><item><title><![CDATA[Reply to SQL-Verbindung aufbauen (c++) on Tue, 04 Sep 2007 11:24:24 GMT]]></title><description><![CDATA[<p>eine verbindung zu einer sql datenbank, meine güte^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1358668</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1358668</guid><dc:creator><![CDATA[legion]]></dc:creator><pubDate>Tue, 04 Sep 2007 11:24:24 GMT</pubDate></item><item><title><![CDATA[Reply to SQL-Verbindung aufbauen (c++) on Tue, 04 Sep 2007 11:29:52 GMT]]></title><description><![CDATA[<p><a href="http://msdn2.microsoft.com/en-us/library/ms714177.aspx" rel="nofollow">http://msdn2.microsoft.com/en-us/library/ms714177.aspx</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1358675</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1358675</guid><dc:creator><![CDATA[teppichmensch]]></dc:creator><pubDate>Tue, 04 Sep 2007 11:29:52 GMT</pubDate></item><item><title><![CDATA[Reply to SQL-Verbindung aufbauen (c++) on Tue, 04 Sep 2007 11:32:53 GMT]]></title><description><![CDATA[<p>MySQL: <a href="http://c-plusplus.net/forum/viewtopic-var-t-is-173240.html" rel="nofollow">http://c-plusplus.net/forum/viewtopic-var-t-is-173240.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1358678</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1358678</guid><dc:creator><![CDATA[oder]]></dc:creator><pubDate>Tue, 04 Sep 2007 11:32:53 GMT</pubDate></item><item><title><![CDATA[Reply to SQL-Verbindung aufbauen (c++) on Tue, 04 Sep 2007 11:38:11 GMT]]></title><description><![CDATA[<p>Hi,</p>
<pre><code>#define MAXBUFLEN   255

SQLHENV      henv = SQL_NULL_HENV;
SQLHDBC      hdbc1 = SQL_NULL_HDBC;
SQLHSTMT      hstmt1 = SQL_NULL_HSTMT;

SQLCHAR      ConnStrIn[MAXBUFLEN] =
         &quot;DRIVER={SQL Server};SERVER=MyServer&quot;;

SQLCHAR      ConnStrOut[MAXBUFLEN];
SQLSMALLINT   cbConnStrOut = 0;

// Make connection without data source. Ask that driver 
// prompt if insufficient information. Driver returns
// SQL_ERROR and application prompts user
// for missing information. Window handle not needed for
// SQL_DRIVER_NOPROMPT.
retcode = SQLDriverConnect(hdbc1,      // Connection handle
                  NULL,         // Window handle
                  ConnStrIn,      // Input connect string
                  SQL_NTS,         // Null-terminated string
                  ConnStrOut,      // Address of output buffer
                  MAXBUFLEN,      // Size of output buffer
                  &amp;cbConnStrOut,   // Address of output length
                  SQL_DRIVER_PROMPT);
</code></pre>
<p>Das ist aus der MSDN. Für Abfragen und weiteres steht da natürlich auch alles drinn.<br />
Achja und im Magazin gibt es Artikel über die MFC Klassen CRecordset und CDatabase mit dennen ich auch gute Erfahrungen gemacht habe.<br />
MfG schirrmie</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1358680</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1358680</guid><dc:creator><![CDATA[schirrmie]]></dc:creator><pubDate>Tue, 04 Sep 2007 11:38:11 GMT</pubDate></item><item><title><![CDATA[Reply to SQL-Verbindung aufbauen (c++) on Tue, 04 Sep 2007 11:44:19 GMT]]></title><description><![CDATA[<p>Was willst du verwenden?<br />
ADO, OLEDB, ODBC ...?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1358685</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1358685</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Tue, 04 Sep 2007 11:44:19 GMT</pubDate></item><item><title><![CDATA[Reply to SQL-Verbindung aufbauen (c++) on Tue, 04 Sep 2007 11:45:42 GMT]]></title><description><![CDATA[<p>eigentlich wollt ich ADO verwenden^^<br />
wie gesagt...ich hab vorher nie ne DB-Verbindung hergestellt^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1358688</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1358688</guid><dc:creator><![CDATA[legion]]></dc:creator><pubDate>Tue, 04 Sep 2007 11:45:42 GMT</pubDate></item><item><title><![CDATA[Reply to SQL-Verbindung aufbauen (c++) on Tue, 04 Sep 2007 12:11:01 GMT]]></title><description><![CDATA[<p>also mir wurde gesagt ich soll irgendwie den native driver benutzen...<br />
und das die anmeldung über windows authentification läuft...<br />
dazu hab ich dann noch den server namen...mehr hab ich nicht &gt;.&gt;<br />
Echt absolut keine Ahnung... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title="=("
      alt="😞"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1358719</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1358719</guid><dc:creator><![CDATA[legion]]></dc:creator><pubDate>Tue, 04 Sep 2007 12:11:01 GMT</pubDate></item><item><title><![CDATA[Reply to SQL-Verbindung aufbauen (c++) on Tue, 04 Sep 2007 12:37:28 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#define MAXBUFLEN   255

SQLHENV		henv = SQL_NULL_HENV;
SQLHDBC		hdbc1 = SQL_NULL_HDBC;
SQLHSTMT	hstmt1 = SQL_NULL_HSTMT;
SQLRETURN	retcode;
SQLCHAR		ConnStrIn[MAXBUFLEN] =&quot;DRIVER={SQL Native Client};SERVER=(base-server3);Trusted_Connection=yes&quot;;

SQLCHAR		ConnStrOut[MAXBUFLEN];
SQLSMALLINT	cbConnStrOut = 0;

// Make connection without data source. Ask that driver
// prompt if insufficient information. Driver returns
// SQL_ERROR and application prompts user
// for missing information. Window handle not needed for
// SQL_DRIVER_NOPROMPT.
retcode = SQLDriverConnectA(hdbc1,NULL,ConnStrIn,SQL_NTS,ConnStrOut,MAXBUFLEN,&amp;cbConnStrOut,SQL_DRIVER_PROMPT);
cout &lt;&lt; retcode;
SQLDisconnect(hdbc1);
</code></pre>
<p>das cout gibt mir nen -2 aus...jemand ne ahnung was das zu bedeuten hat?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1358746</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1358746</guid><dc:creator><![CDATA[legion]]></dc:creator><pubDate>Tue, 04 Sep 2007 12:37:28 GMT</pubDate></item><item><title><![CDATA[Reply to SQL-Verbindung aufbauen (c++) on Tue, 04 Sep 2007 14:00:57 GMT]]></title><description><![CDATA[<p>also ich brauch nen connectionstring der halt die wichtigen &quot;daten&quot; beinhaltet<br />
wir benutzen MS SQL Server 2005</p>
<p>der string sieht so aus bisher<br />
Driver={SQL Native Client};Server=base-server3;Database=******;Trusted_Connection=yes;</p>
<p>aber wie benutz ich den? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title="=("
      alt="😞"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1358813</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1358813</guid><dc:creator><![CDATA[legion]]></dc:creator><pubDate>Tue, 04 Sep 2007 14:00:57 GMT</pubDate></item><item><title><![CDATA[Reply to SQL-Verbindung aufbauen (c++) on Tue, 04 Sep 2007 14:36:13 GMT]]></title><description><![CDATA[<p>Ich persönlich würde es über ADO machen. ADO geht dann über OLEDB und OLEDB verwendet den &quot;native SQL driver&quot; (oder wie der genau heisst, geht auf jeden Fall NICHT über ODBC).<br />
Ist für mich &quot;direkt genug&quot;. Am Server braucht dazu nix installiert zu werden, Connection kann über Named Pipes oder TCP/IP Port 1433 laufen, Connection String sieht dann z.B. so aus (für Port 1433):</p>
<pre><code>provider=SQLOLEDB;data source=SERVERNAME;initial catalog=DATABASENAME;integrated security=SSPI;application name=Hotzenplotz;network library=dbmssocn;
</code></pre>
<p>Ahja, am Client muss evtl. das aktuelle MDAC (Microsoft Data Access Components) installiert werden, welches bei Windows XP und Server 2003 aber schon dabei ist, muss man also üblicherweise auch nix installieren.</p>
<p>p.S.: &quot;Ich persönlich würde es über ADO machen&quot; einfach deswegen, weil ich mit ADO schon viel gearbeitet habe, die Geschwindigkeit immer ausreichen war, und ich das Interface schön einfach finde. Natürlich spricht auch nix gegen OLEDB direkt oder sonstwas, wenn man sich damit anfreunden kann.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1358845</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1358845</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Tue, 04 Sep 2007 14:36:13 GMT</pubDate></item><item><title><![CDATA[Reply to SQL-Verbindung aufbauen (c++) on Tue, 04 Sep 2007 14:37:29 GMT]]></title><description><![CDATA[<p>mh...und wie benutze ich diesen connectionstring dann?<br />
ich such hier schon stundenlang nach irgendeiner guten lösung...werd aber nich fündig <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title="=("
      alt="😞"
    /></p>
<p>bzw....wie kann ich denn testen ob die connection funktioniert?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1358849</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1358849</guid><dc:creator><![CDATA[legion]]></dc:creator><pubDate>Tue, 04 Sep 2007 14:37:29 GMT</pubDate></item><item><title><![CDATA[Reply to SQL-Verbindung aufbauen (c++) on Tue, 04 Sep 2007 15:03:21 GMT]]></title><description><![CDATA[<p>In dem code den du (und ich) gepostet hattest benutzt du doch schon ein Connectionstring. Hier noch ne seite für dich <a href="http://www.connectionstrings.com/" rel="nofollow">http://www.connectionstrings.com/</a><br />
Da stehen alle möglichen drinn. Was klappt denn genau nicht?</p>
<p>schirrmie</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1358878</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1358878</guid><dc:creator><![CDATA[schirrmie]]></dc:creator><pubDate>Tue, 04 Sep 2007 15:03:21 GMT</pubDate></item><item><title><![CDATA[Reply to SQL-Verbindung aufbauen (c++) on Tue, 04 Sep 2007 15:29:36 GMT]]></title><description><![CDATA[<p>also mir wurde gerade gesagt dass diese -2 zu bedeuten hat, dass die verbindung steht.....und ich such mich hier dumm und dämlich...</p>
<p>jetzt würd ich gern testen ob ich irgendwas aus der tabelle auslesen kann...kenne aber den syntax nicht <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title="=("
      alt="😞"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1358902</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1358902</guid><dc:creator><![CDATA[legion]]></dc:creator><pubDate>Tue, 04 Sep 2007 15:29:36 GMT</pubDate></item><item><title><![CDATA[Reply to SQL-Verbindung aufbauen (c++) on Tue, 04 Sep 2007 15:52:41 GMT]]></title><description><![CDATA[<p>Wie wärs wenn du mal selbst dein Kopf anstrengst und suchst, die MSDN wurde hier schon mehrfach genannt und das nicht ohne Grund <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Das ist nur Ein Bsp. aus der MSDN und hast du dir den Artikel hier im Magazin (ganz unten im Forum) mal durchgelesen?</p>
<pre><code>#define NAME_LEN 50
#define PHONE_LEN 50

SQLCHAR      szName[NAME_LEN], szPhone[PHONE_LEN];
SQLINTEGER   sCustID, cbName, cbAge, cbBirthday;
SQLRETURN    retcode;
SQLHSTMT     hstmt;

retcode = SQLExecDirect(hstmt,
   &quot;SELECT CUSTID, NAME, PHONE FROM CUSTOMERS ORDER BY 2, 1, 3&quot;,
   SQL_NTS);

if (retcode == SQL_SUCCESS) {
   while (TRUE) {
      retcode = SQLFetch(hstmt);
      if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
         show_error();
      }
      if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO){

         /* Get data for columns 1, 2, and 3 */

         SQLGetData(hstmt, 1, SQL_C_ULONG, &amp;sCustID, 0, &amp;cbCustID);
         SQLGetData(hstmt, 2, SQL_C_CHAR, szName, NAME_LEN, &amp;cbName);
         SQLGetData(hstmt, 3, SQL_C_CHAR, szPhone, PHONE_LEN,
            &amp;cbPhone);

         /* Print the row of data */

         fprintf(out, &quot;%-5d %-*s %*s&quot;, sCustID, NAME_LEN-1, szName, 
            PHONE_LEN-1, szPhone);
      } else {
         break;
      }
   }
}
</code></pre>
<p>schirrmie</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1358915</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1358915</guid><dc:creator><![CDATA[schirrmie]]></dc:creator><pubDate>Tue, 04 Sep 2007 15:52:41 GMT</pubDate></item><item><title><![CDATA[Reply to SQL-Verbindung aufbauen (c++) on Thu, 06 Sep 2007 11:01:55 GMT]]></title><description><![CDATA[<p>mhh...okay...danke..<br />
bei der msdn such ich die ganze zeit schon^^<br />
und auch hier im forum..<br />
aber hab vorher nie mit ner DB gearbeitet.</p>
<p>aber irgendwie scheint der sich doch nicht verbunden zu haben....und wirklich keine ahnung wieso...kommt auf jedenfalls nen SQL_ERROR nach SQLDRIVERCONNECT raus<br />
zugriffsrechte auf den server hab ich...mein kollege weiß auch nicht woran das liegen kann <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title="=("
      alt="😞"
    /></p>
<p>hab auch alle möglichen connectionsstrings ausprobiert...also in verschiedenen formen und so...<br />
aber das funkzt einfach nich... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>hier mal der sourcecode...</p>
<pre><code class="language-cpp">int cl_event::sql_open()
{

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

SQLCHAR InConnStr[255]=&quot;Driver={SQL Server};Server=BASE-1;Database=TESTDB;Trusted_Connection=yes;Network=dbnmpntw;&quot;;

SQLWCHAR OutConnStr[255];
SQLSMALLINT OutConnStrLen;

// Allocate environment handle
retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &amp;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, &amp;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,
255, 
&amp;OutConnStrLen,
SQL_DRIVER_NOPROMPT ); 

		// Allocate statement handle
		if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {              
		retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &amp;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;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1360077</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1360077</guid><dc:creator><![CDATA[legion]]></dc:creator><pubDate>Thu, 06 Sep 2007 11:01:55 GMT</pubDate></item></channel></rss>