SqlConnection字符串问题 [英] SqlConnection String issue

查看:127
本文介绍了SqlConnection字符串问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


嘿,

我们有一个Windows服务连接到SQL Server 2005.我们得到以下错误消息

We have a windows service connects to a sql server 2005. we got following error message

用户''登录失败。用户未与受信任的SQL Server连接关联。

Login failed for user ''. The user is not associated with a trusted SQL Server connection.

在审核代码之后,我们知道connectionstring中缺少integratedsecurity = true。我们理解修改代码将解决此问题,但我们正在寻找一种替代解决方案来解决此问题,而无需修改代码。经过一番研究,我们知道在托管windiws服务的机器和SQL Server 2005之间添加可信关系可以解决这个问题。
我们有另一种解决方法吗?

After review code, we know the integratedsecurity=true was missing in connectionstring. We understand modify code will fix
this problem but we are looking for an alternative solution fixing this issue without modify code. After a little research,
we know adding trusted relationship between the machine hosting windiws service and SQL server 2005 can fix this issue.
Do we have another way to fix this?

此外,我们在配置文件中有DataSource和Initial catelog。 SqlConnectionStringBuilder基于这些值中的值构建连接字符串。是否可以将IntegratedSecurity = True放入host或name的值中。所以我们可以有一个值为IntegratedSecurity的连接字符串。

Also, we have DataSource and Initial catelog in configuration files. SqlConnectionStringBuilder build up connectionstring based on value in those values. Does there have a way to put IntegratedSecurity=True into the value of host or name. So we can have a connectionstring with value of IntegratedSecurity.

< add key =" MainDatabaseHost"值= QUOT; XXXX" />
< add key =" MainDatabaseName"值= QUOT; YYYYYYYY" />

   <add key="MainDatabaseHost" value="xxxx" />
   <add key="MainDatabaseName" value="yyyyyyyy" />


谢谢,

推荐答案

全部您需要做的是将整个连接字符串存储在.config文件的ConnectionStrings配置部分中。在这种情况下,您无需更改任何代码。存储连接字符串是一种优选的方式,允许您随时更改它们而无需修改应用程序,并提供良好的可维护性。我不明白为什么你需要存储连接字符串的单独部分,然后在代码内部构建它。


这篇关于SqlConnection字符串问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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