下面是我的代码
BOOL CDemoApp::InitInstance()
{
AfxOleInit();///初始化COM库
////////////连接数据库//////////////
HRESULT hr;
try
{
hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象
if(SUCCEEDED(hr))
hr = m_pConnection->Open("Provider=SQLOLEDB;data source=Yl001;initial catalog=Yl001;userid=sa;password=;","","",adModeUnknown);///连接数据库
}
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);///显示错误信息
}
11 个解决方案
#1
好象data source=????不对,设置成localhost或者服务器名试一下
#2
Provider=SQLOLEDB 这句改:Provider=SQL SERVER
#3
http://community.csdn.net/Expert/topic/3608/3608767.xml?temp=.710293
#4
hr = m_pConnection->Open("Provider=SQLOLEDB;data source=Yl001;initial catalog=Yl001;userid=sa;password=;","","",adModeUnknown);
--->
hr = m_pConnection->Open("Provider=SQLOLEDB;data source=Yl001;persist security info = false;initial catalog=Yl001;userid=sa;password=;","","",adModeUnknown);
--->
hr = m_pConnection->Open("Provider=SQLOLEDB;data source=Yl001;persist security info = false;initial catalog=Yl001;userid=sa;password=;","","",adModeUnknown);
#5
各位大哥,我照你们说的改了,错误还是一样的阿
#6
不介意的话,代码发给我,我帮你看看:
bohut@163.com
bohut@163.com
#7
Timeout时间是不是太短了,把Timeout时间设长一点。
#8
请确认你的SQL Server 可不可以用sa 登录。
#9
hr = m_pConnection->Open("Provider=SQLOLEDB.1;data source=Yl001;persist security info = false;initial catalog=Yl001;userid=sa;password=;","","",adModeUnknown);
#10
//建立连接
_ConnectionPtr g_pConn;
g_pConn.CreateInstance(__uuidof(Connection));
g_pConn->Open ("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Abcd;Data Source=ServerName","","",adModeUnknown);
_ConnectionPtr g_pConn;
g_pConn.CreateInstance(__uuidof(Connection));
g_pConn->Open ("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Abcd;Data Source=ServerName","","",adModeUnknown);
#11
是不是你data source=Yl001;initial catalog=Yl001这两个搞错了,我用这样就可以:
hr = m_pConnection->Open("Driver={SQL Server};Server=Yl001;database=Yl001;userid=sa;password=;","sa","",adModeUnknown);///连接数据库
Server为服务器地址
hr = m_pConnection->Open("Driver={SQL Server};Server=Yl001;database=Yl001;userid=sa;password=;","sa","",adModeUnknown);///连接数据库
Server为服务器地址
#1
好象data source=????不对,设置成localhost或者服务器名试一下
#2
Provider=SQLOLEDB 这句改:Provider=SQL SERVER
#3
http://community.csdn.net/Expert/topic/3608/3608767.xml?temp=.710293
#4
hr = m_pConnection->Open("Provider=SQLOLEDB;data source=Yl001;initial catalog=Yl001;userid=sa;password=;","","",adModeUnknown);
--->
hr = m_pConnection->Open("Provider=SQLOLEDB;data source=Yl001;persist security info = false;initial catalog=Yl001;userid=sa;password=;","","",adModeUnknown);
--->
hr = m_pConnection->Open("Provider=SQLOLEDB;data source=Yl001;persist security info = false;initial catalog=Yl001;userid=sa;password=;","","",adModeUnknown);
#5
各位大哥,我照你们说的改了,错误还是一样的阿
#6
不介意的话,代码发给我,我帮你看看:
bohut@163.com
bohut@163.com
#7
Timeout时间是不是太短了,把Timeout时间设长一点。
#8
请确认你的SQL Server 可不可以用sa 登录。
#9
hr = m_pConnection->Open("Provider=SQLOLEDB.1;data source=Yl001;persist security info = false;initial catalog=Yl001;userid=sa;password=;","","",adModeUnknown);
#10
//建立连接
_ConnectionPtr g_pConn;
g_pConn.CreateInstance(__uuidof(Connection));
g_pConn->Open ("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Abcd;Data Source=ServerName","","",adModeUnknown);
_ConnectionPtr g_pConn;
g_pConn.CreateInstance(__uuidof(Connection));
g_pConn->Open ("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Abcd;Data Source=ServerName","","",adModeUnknown);
#11
是不是你data source=Yl001;initial catalog=Yl001这两个搞错了,我用这样就可以:
hr = m_pConnection->Open("Driver={SQL Server};Server=Yl001;database=Yl001;userid=sa;password=;","sa","",adModeUnknown);///连接数据库
Server为服务器地址
hr = m_pConnection->Open("Driver={SQL Server};Server=Yl001;database=Yl001;userid=sa;password=;","sa","",adModeUnknown);///连接数据库
Server为服务器地址