写了一个组件,其中有连接sql server代码。当一般应用程序调用这个组件时没有问题。
但当以service方式运行的程序调用时--出错!!连接数据库代码如下代码 //
CString strConnection;
strConnection.Format("Driver={SQL Server};Server=%s;Trusted_Connection=no;Database=%s;Uid=%s;Pwd=%s;", strServer, "table", strAdmin, strPassword); try{
_ConnectionPtr spConnection;
spConnection.CreateInstance(__uuidof(Connection)); //
m_pConnection->PutCommandTimeout(0); //
spConnection->PutConnectionTimeout(0); //
spConnection->Open(strConnection.AllocSysString(), "", "", NULL); }
catch(_com_error &e)
{
return E_FAIL;
}
但当以service方式运行的程序调用时--出错!!连接数据库代码如下代码 //
CString strConnection;
strConnection.Format("Driver={SQL Server};Server=%s;Trusted_Connection=no;Database=%s;Uid=%s;Pwd=%s;", strServer, "table", strAdmin, strPassword); try{
_ConnectionPtr spConnection;
spConnection.CreateInstance(__uuidof(Connection)); //
m_pConnection->PutCommandTimeout(0); //
spConnection->PutConnectionTimeout(0); //
spConnection->Open(strConnection.AllocSysString(), "", "", NULL); }
catch(_com_error &e)
{
return E_FAIL;
}
所要查询的SQL信息发送的服务器端。如果是服务器端调用控件的话,你的控件必须得是.net FrameWork的控件。直接将MFC的控件在服务器端使用是不行的,还需要将MFC的控件重新做成.net FrameWork的控件。
总结问题如下:
1。以administrator运行一般程序,以上代码可以连接数据库(本地或远程)
2。当以service方式运行时:
。如果sqlserver在本地,以上代码可以连接数据库
。如果sqlserver在另外一台机器上,则以上代码不能连接数据库。总结:如何是使得service方式运行程序可以连接另外一台机器上运行的sqlserver?
好像是权限方面的问题。
设置sql server?
能具体说说在那里设置?--sql server 2005
好像与管理员权限没关吧。