用CDatabase必须用ODBC连,MSDN上说: To work with classCDatabase, the data source must be one that you have configured through Open Database Connectivity (ODBC) Administrator. Examples of data sources include a remote database running on Microsoft SQL Server across a network, or a Microsoft Access file in a local directory. From your application, you can access any data source for which you have an ODBC driver. You can have one or more data sources active in your application at one time, each represented by a CDatabase object. You can also have multiple simultaneous connections to any data source. You can connect to remote as well as to local data sources, depending on the drivers you have installed and the capabilities of your ODBC drivers. CDatabase 的第三个参数: lpszConnectSpecifies a connect string. The connect string concatenates information, possibly including a data source name, a user ID valid on the data source, a user authentication string (password, if the data source requires one), and other information. The whole connect string must be prefixed by the string “ODBC;” (uppercase or lowercase). The “ODBC;” string is used to indicate that the connection is to an ODBC data source; this is for upward compatibility when future versions of the class library might support non-ODBC data sources.
我是这么写的:
m_database->Open(NULL,FALSE,FALSE,"driver={SQL Server};Server=Server1;DATABASE=Db;UID=sa;PWD=sa",FALSE)
不对吗?
To work with classCDatabase, the data source must be one that you have configured through Open Database Connectivity (ODBC) Administrator. Examples of data sources include a remote database running on Microsoft SQL Server across a network, or a Microsoft Access file in a local directory. From your application, you can access any data source for which you have an ODBC driver. You can have one or more data sources active in your application at one time, each represented by a CDatabase object. You can also have multiple simultaneous connections to any data source. You can connect to remote as well as to local data sources, depending on the drivers you have installed and the capabilities of your ODBC drivers. CDatabase 的第三个参数:
lpszConnectSpecifies a connect string. The connect string concatenates information, possibly including a data source name, a user ID valid on the data source, a user authentication string (password, if the data source requires one), and other information. The whole connect string must be prefixed by the string “ODBC;” (uppercase or lowercase). The “ODBC;” string is used to indicate that the connection is to an ODBC data source; this is for upward compatibility when future versions of the class library might support non-ODBC data sources.