Winodw服务无法打开数据库 [英] Winodw service cann't open database

查看:142
本文介绍了Winodw服务无法打开数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi
为什么

Hi why

CDatabase

无法在运行时在Window Service中打开?(它是VC ++窗口服务)



can't open in Window Service in runtime?(it's VC++ window service)

CString sConnectionString = L"ODBC;DSN=MyDB;Trusted_Connection=Yes";
CDatabase db;
db.SetLoginTimeout(8000);
db.SetQueryTimeout(8000);
db.Open( NULL, 0, 0, sConnectionString );





如果这个exe作为控制台应用程序运行,数据库打开正确。但是当它作为服务管理器中的窗口服务运行时,它无法打开数据库!!!

请帮助我!



我尝试过:





If this exe , runs as a console app, the Database opens right . But when it runs as a window service in service Manager, it cann't open Database!!!
please help me!

What I have tried:

why winodw service cann't open Database? (CDatabase.Open())

推荐答案

这可能是因为您在连接字符串中使用了可信连接。



使用可信连接意味着提交给数据库登录的用户凭据是运行代码的用户凭据。在您的数据库代码工作的情况下,代码以您的身份运行。



如果Windows服务没有打开数据库,那么你很可能真的很好'重新运行本地系统帐户下的代码,该帐户不具有对数据库的访问权限。



删除连接字符串的可信连接部分并替换它使用具有相应权限登录该数据库的帐户的用户名和密码。



您可能必须在SQL Server上专门创建一个帐户这个数据库。
It's probably because you're using a trusted connection in your connection string.

Using a Trusted Connection means that the user credentials presented to the database to login are the ones the code is running under. In the case where your database code works, the code is running as YOU.

In the case of the Windows service not opening the database, chances are really good you're running the code under the Local System account, which will NOT have access permissions to your database.

Get rid of the Trusted Connection part of your connection string and replace it with a username and password of an account that does have appropriate permissions to login to that database.

You'll probably have to create an account on the SQL Server specifically for this database.


这篇关于Winodw服务无法打开数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆