⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 odbc2.html

📁 win32汇编教程 希望各位多多支持
💻 HTML
📖 第 1 页 / 共 3 页
字号:
    The length of the DSN string</font></li>
  <li><font color="#FFCCFF"><b><font face="Tahoma" size="-1">pUserName</font></b></font><font face="Tahoma" size="-1">. 
    Pointer to the user name string</font></li>
  <li><font color="#FFCCFF"><b><font face="Tahoma" size="-1">NameLength</font></b></font><font face="Tahoma" size="-1">. 
    The length of the user name string</font></li>
  <li><font color="#FFCCFF"><b><font face="Tahoma" size="-1">pPassword</font></b></font><font face="Tahoma" size="-1">. 
    Pointer to the password associated with the user name</font></li>
  <li><font color="#FFCCFF"><b><font face="Tahoma" size="-1">PasswordLength</font></b></font><font face="Tahoma" size="-1">. 
    The length of the password</font></li>
</ul>
<p><font face="Tahoma" size="-1">At the mininum, <font color="#FFFFCC"><b>SQLConnect</b></font> 
  requires the connection handle, DSN and its length: user name and password are 
  optional if the data source doesn't require them. The list of possible return 
  values is identical to that of <font color="#FFFFCC"><b>SQLAllocHandle</b></font>.</font></p>
<p><font face="Tahoma" size="-1">Assuming you have a DSN named &quot;Sales&quot; 
  in your system and you want to connect to it. You can do it like this:</font></p>
<p><font face="Tahoma" size="-1"><b><font color="#33CCCC">.data<br>
  DSN db &quot;Sales&quot;,0</font></b></font></p>
<p><font color="#33CCCC"><b><font face="Tahoma" size="-1">.code<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;......<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke SQLConnect, hConn, 
  addr DSN, sizeof DSN,0,0,0,0</font></b></font></p>
<p><font face="Tahoma" size="-1">One disadvantage of <font color="#FFFFCC"><b>SQLConnect</b></font> 
  is that, you have to create a DSN before you can connect to the data source.<font color="#FFFFCC"><b> 
  SQLDriverConnect </b></font>offers more flexibility. It has the following syntax:</font></p>
<blockquote> 
  <pre><b><font face="Tahoma" color="#CCFFCC">SQLDriverConnect proto ConnectionHandle:DWORD,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hWnd:DWORD,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pInConnectString:DWORD,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InStringLength:DWORD,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pOutConnectString:DWORD,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OutBufferSize:DWORD,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pOutConnectStringLength:DWORD,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DriverCompletion:DWORD</font></b></pre>
</blockquote>
<ul>
  <li><b><font face="Tahoma" color="#CCFFCC"><br>
    <font color="#FFCCFF" size="-1">ConnectionHandle </font></font></b><font face="Tahoma" size="-1">The 
    handle to the connection</font></li>
  <li><font face="Tahoma" size="-1"><b><font color="#FFCCFF">hWnd</font></b> The 
    handle to your window. If you pass NULL as this parameter, the driver will 
    not prompt the user with a dialog box for more information (if needed).</font></li>
  <li><font color="#FFCCFF" size="-1"><b><font face="Tahoma">pInConnectString</font></b></font><font face="Tahoma" size="-1"> 
    The pointer to the connection string. This is an ASCIIZ string that follows 
    the format described by the specific ODBC driver you want to connect to. It 
    describes the name of the driver and the data source and additional attributes. 
    The full description of connection string is available in MSDN. I won't go 
    into detail here.</font></li>
  <li><font color="#FFCCFF" size="-1"><b><font face="Tahoma">InStringLength</font></b></font><font face="Tahoma" size="-1"> 
    The length of the connect string.</font></li>
  <li><font face="Tahoma" size="-1"><b><font color="#FFCCFF">pOutConnectString</font></b> 
    The pointer to the buffer that will be filled with the complete connection 
    string. The size of this buffer should be at least 1,024 bytes. This may sound 
    confusing. The connection string you passed to the function may not be complete. 
    In that case, the ODBC driver may prompt the user for more information. The 
    ODBC driver then constructs the complete connection string from all available 
    information and puts it in the buffer. Even if the connection string you supplied 
    was functional, this buffer will be filled with more attributes. The purpose 
    of this parameter is so you can save the complete connection string for future 
    connection.</font></li>
  <li><font color="#FFCCFF"><b><font face="Tahoma" size="-1">OutBufferSize </font></b></font><font face="Tahoma" size="-1">The 
    size of the buffer pointed to by <font color="#FFCCFF"><b>pOutConnectString</b></font>.</font></li>
  <li><font color="#FFCCFF"><b><font face="Tahoma" size="-1">pOutConnectStringLength</font></b></font><font face="Tahoma" size="-1"> 
    The pointer to a dword variable that will receive the actual length of the 
    complete connection string returned by the ODBC driver.</font></li>
  <li><font color="#FFCCFF"><b><font face="Tahoma" size="-1">DriverCompletion</font></b></font><font face="Tahoma" size="-1"> 
    A flag that specifies whether the ODBC manager/driver will prompt the user 
    for more information. However, the flag depends on whether you pass a window 
    handle to <font color="#FFCCFF"><b>hWnd </b></font>parameter of <font color="#FFFFCC"><b>SQLDriverConnect</b></font>. 
    If you didn't, the ODBC manager/driver won't prompt the user even if this 
    flag instructs it to.<br>
    <br>
    </font> 
    <table border="1" cellspacing="1" cellpadding="3" align="center">
      <tr> 
        <td bgcolor="#003366"><b><font face="Tahoma" size="-1">SQL_DRIVER_PROMPT</font></b></td>
        <td bgcolor="#006666"><font face="Tahoma" size="-1">The ODBC driver prompts 
          the user for information. It uses the information to construct the connection 
          string.</font></td>
      </tr>
      <tr> 
        <td bgcolor="#003366"><b><font face="Tahoma" size="-1">SQL_DRIVER_COMPLETE<br>
          SQL_DRIVER_COMPLETE_REQUIRED </font></b></td>
        <td bgcolor="#006666"><font face="Tahoma" size="-1">The ODBC driver will 
          prompt the user only if the connection string supplied by your program 
          is not complete.</font></td>
      </tr>
      <tr> 
        <td bgcolor="#003366"><b><font face="Tahoma" size="-1">SQL_DRIVER_NOPROMPT</font></b></td>
        <td bgcolor="#006666"><font face="Tahoma" size="-1">The ODBC driver won't 
          prompt the user for more information.</font></td>
      </tr>
    </table>
    <font face="Tahoma" size="-1"> </font></li>
</ul>
<p><font face="Tahoma" size="-1"><b><font color="#33CCCC">Example:</font></b></font></p>
<p><font color="#33CCCC"><b><font face="Tahoma" size="-1">.data<br>
  strConnect db "DBQ=c:\data\test.mdb;DRIVER={Microsoft Access Driver (*.mdb)};&quot;,0 
  </font></b></font></p>
<p><font color="#33CCCC"><b><font face="Tahoma" size="-1">.data?<br>
  buffer db 1024 dup(?)<br>
  OutStringLength dd ?</font></b></font></p>
<p><font color="#33CCCC"><b><font face="Tahoma" size="-1">.code<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.....<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;invoke SQLDriverConnect, hConn, hWnd, addr strConnect, 
  sizeof strConnect, addr buffer, sizeof buffer, addr OutBufferLength, SQL_DRIVER_COMPLETE</font></b></font></p>
<h4><font face="Tahoma" color="#FFFFCC">Disconnecting from the data source</font></h4>
<p><font face="Tahoma" size="-1">After the connection is made successfully, you 
  can construct one or more statements and query the data source. I'll examine 
  that part in the next tutorial. For now, let's assume you're done with the data 
  source, you need to disconnect from it by calling <font color="#FFFFCC"><b>SQLDisconnect</b></font>. 
  This function is quite simple (Reflecting the harsh and sad reality that destruction 
  is much easier than construction). It takes only one parameter, the connection 
  handle.</font></p>
<blockquote> 
  <p><font face="Tahoma" size="-1"><b><font color="#33CCCC">invoke SQLDisconnect, 
    hConn</font></b></font></p>
</blockquote>
<h4><font color="#FFFFCC" face="Tahoma">Freeing the connection and environment 
  handles</font></h4>
<p><font face="Tahoma" size="-1">After the successful disconnect, you can now 
  destroy the connection and environment handles by calling <font color="#FFFFCC"><b>SQLFreeHandle</b></font>. 
  This is a new function introduced in ODBC 3.x. It supersedes <font color="#FFFFCC"><b>SQLFreeConnect</b></font>, 
  <font color="#FFFFCC"> <b>SQLFreeEnv</b></font> and <font color="#FFFFCC"><b>SQLFreeStmt</b></font>. 
  SQLFreeHandle has the following syntax:</font></p>
<blockquote> 
  <pre><font face="Tahoma"><b><font color="#CCFFCC">SQLFreeHandle proto HandleType:DWORD, Handle:DWORD</font></b></font></pre>
</blockquote>
<ul>
  <li><font color="#FFCCFF"><b><font face="Tahoma" size="-1">HandleType</font></b></font><font face="Tahoma" size="-1"> 
    is a constant that identifies the type of handle you passed to this function 
    as the second parameter. The possible values are the same as those used in 
    <font color="#FFFFCC"> <b>SQLAllocHandle</b></font></font></li>
  <li><font color="#FFCCFF"><b><font face="Tahoma" size="-1">Handle</font></b></font><font face="Tahoma" size="-1"> 
    is the handle you want to destroy.</font></li>
</ul>
<p><font face="Tahoma" size="-1">For example:</font></p>
<blockquote> 
  <p><font face="Tahoma" size="-1"><b><font color="#33CCCC">invoke SQLFreeHandle, 
    SQL_HANDLE_DBC, hConn<br>
    invoke SQLFreeHandle, SQL_HANDLE_ENV, hEnv</font></b></font></p>
</blockquote>
<hr>
<p align="center"><b><font face="Tahoma" size="-1">[<a href="http://win32asm.cjb.net">Iczelion's 
  Win32 Assembly Homepage</a>]</font></b></p>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -