ADO连接数据库的connectionstring设置

eaglec 2005-03-29 05:31:41
void CShow::LoginSQL()
{
_bstr_t strConnect="Provider=SQLOLEDB; Server = localhost; Database = 预测数据;uid=SLF; pwd=0736";
HRESULT hr=((CSLFApp*)AfxGetApp())->m_pConnection.CreateInstance(__uuidof(Connection));
if(FAILED(hr))return ;
try
{
((CSLFApp*)AfxGetApp())->m_pConnection->Open(strConnect,"","",adModeUnknown);
}
catch(_com_error e)
{
AfxMessageBox("数据库连接失败!");
}
}
请问大侠在以上参数设置中,sever=localhost是否意味着按装sql server时要选用默认实例才能连接成功?若我安装了另外一个实例,为什么把这个server设置成计算机名\实例名后,服务器就不能与程序连接?
ps:我在xp profession版上安装的sql server个人版,在执行程序时,已确保服务器运行。
另外,连接上数据库后,却又出现runtime error是怎么回事?
...全文
215 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
AkiraChing 2005-04-01
  • 打赏
  • 举报
回复
strConnect = _T("Provider=sqloledb;Network Library=DBMSSOCN;"
"Data Source=130.120.110.001,1433;"
"Initial Catalog=MyDatabaseName;User ID=MyUsername;"
"Password=MyPassword;");
AkiraChing 2005-04-01
  • 打赏
  • 举报
回复
OLE DB Provider for Sql Server
For Standard Security:
For Trusted Connection security: (Microsoft Windows NT integrated security):
If you want to connect ta a "Named Instance" (SQL Server 2000) you must to specifiy Data Source=Servere
Name\Instance Name like in the following example:
If you want To connect with a SQL Server running on the same computer, you must to specify the keyword (local) in the
Data Source like in the following example:
To connect to SQL Server running on a remote computer ( via an IP address):

4,017

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧