SQLConfigDataSource(NULL,ODBC_ADD_DSN,"Microsoft Access Driver (*.mdb)\0","DSN=SunwaveRepeaterOMC DBQ=pub.mdb");
解决方案 »
- SleepEx(100,true)出现0x00000000 处未处理的异常: 0xC0000005: Access violation问题
- IShellLink如何使用?
- 如何获得2个CTime之间的时间差,需要达到毫秒!
- Help:有关VC和Directx
- CHtmlView做简单的浏览器,弹新窗口总调IE??
- 我想问一个关于移动文件后出现的问题:)
- 一定给分,请问现在学习vc6.0是不是晚了
- (菜问题)请问如何打包vc++程序!????
- hook CreateFileA 以后很多程序不能访问网络
- 关于使用全局函数的问题!!
- 高手指点,最好举例.
- 我有一个sql数据库连接光出错,我的服务器是ppp,数据库名称是test
#include <stdio.h>
#include <windows.h>
#include "sql.h"
#include <odbcinst.h>int main()
{
RETCODE retcode;UCHAR *szDriver = "SQL Server";
UCHAR *szAttributes =
"DSN=MyDSN\0DESCRIPTION=SQLConfigDSN Sample\0"
"SERVER=MySQL\0ADDRESS=MyServer\0NETWORK=dbmssocn\0"
"DATABASE=pubs\0";retcode = SQLConfigDataSource(NULL,
ODBC_ADD_DSN,
szDriver,
szAttributes);B. 创建文件数据源
在 SQLDriverConnect 中使用 SAVEFILE 关键字创建文件数据源,然后使用 SQLDriverConnect 与该文件数据源进行连接。这是删除错误处理后的简化示例。#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <sql.h>
#include <sqlext.h>
#include <odbcss.h>#define MAXBUFLEN 255SQLHENV henv = SQL_NULL_HENV;
SQLHDBC hdbc1 = SQL_NULL_HDBC;int main() { RETCODE retcode; // This format of the SAVEFILE keyword saves a successful
// connection as the file Myfiledsn.dsn in the ODBC default
// directory for file DSNs.
SQLCHAR szConnStrIn[MAXBUFLEN] =
"SAVEFILE=MyFileDSN;DRIVER={SQL Server};SERVER=MySQL;"
"NETWORK=dbmssocn;UID=sa;PWD=MyPassWord;"; SQLCHAR szConnStrOut[MAXBUFLEN];
SQLSMALLINT cbConnStrOut = 0; // Allocate the ODBC Environment and save handle.
retcode = SQLAllocHandle (SQL_HANDLE_ENV, NULL, &henv); //Notify ODBC that this is an ODBC 3.0 application.
retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION,
(SQLPOINTER) SQL_OV_ODBC3, SQL_IS_INTEGER); // Allocate an ODBC connection handle and connect.
retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc1);
retcode = SQLDriverConnect(hdbc1, // Connection handle
NULL, // Window handle
szConnStrIn, // Input connect string
SQL_NTS, // Null-terminated string
szConnStrOut, // Addr of output buffer
MAXBUFLEN, // Size of output buffer
&cbConnStrOut, // Address of output length
SQL_DRIVER_NOPROMPT); // Disconnect, set up a new connect string, and then test file DSN.
SQLDisconnect(hdbc1);
strcpy(szConnStrIn, "FILEDSN=MyFileDSN;UID=sa;PWD=MyPassWord;");
retcode = SQLDriverConnect(hdbc1, // Connection handle
NULL, // Window handle
szConnStrIn, // Input connect string
SQL_NTS, // Null-terminated string
szConnStrOut, // Addr of output buffer
MAXBUFLEN, // Size of output buffer
&cbConnStrOut, // Address of output length
SQL_DRIVER_NOPROMPT); /* Clean up. */
SQLDisconnect(hdbc1);
SQLFreeHandle(SQL_HANDLE_DBC, hdbc1);
SQLFreeHandle(SQL_HANDLE_ENV, henv);
return(0);
}