在 Win7 下 VS2005 中 VC 使用 ADO 连接数据库时字符集为非 Unicode ,连接代码如下:
CoInitialize(NULL); _ConnectionPtr pConn(__uuidof(Connection)); _RecordsetPtr pRst(__uuidof(Recordset)); pConn->ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=123123;Initial Catalog=MyTest;Data Source=KANG-PC\SQL2005"; //需连接数据库: MyTest //服务器名: KANG-PC\SQL2005 //登陆用户: sa //登入密码: 123123 pConn->Open("","","",adConnectUnspecified);
连接字符串是在 VB 中利用 Microsoft Ado Data Control 控件中取得,并成功连接数据库.(记得在以前用 VC6.0 时候利用这个字符串就可以连接数据库了),可是这里出现错误.由 try catch 捕获到的错误信息:
未指定的错误 //由 e.ErrorMessage() 获得 012FEF78 //由 e.ErrorInfo() 获得 [DBNETLIB][ConnectionOpen (Connect()).]SQL Server 不存在或拒绝访问。//由 e.Description() 获得
Inferred from your error message:
1. Your initial catalog or data source configuration is incorrect;
2. Your database instance is configured incorrectly.
Personally, I think the first possibility is most likely. Windows provides a connection file called dsn to facilitate testing of database connectivity issues. You can try it.