存储用户名和密码以从没有集成安全性的 Windows 服务访问 SQL Server
我们有一个访问 SQL Server 的服务,客户端没有使用集成安全性,并且我们需要该服务在计算机打开时拥有对数据库的权限。我们必须存储 SQL Server 用户名和密码吗?如果是的话在哪里? (以及如何)
We have a service that accesses SQL Server, the client is not using Integrated Security and we need the service to have rights to the database whenever the machine is turned on. Do we have to store the SQL Server username and password? If so where? (and how)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要为此服务创建 SQL 登录 (http://msdn.microsoft.com/en-us/library/aa337562.aspx)。此 SQL 登录的用户名/密码需要存储在服务可以访问的某个位置(应用程序配置/注册表)。
每当您存储凭据时,请对其进行加密,以便其他人无法以明文形式看到该凭据。您还可以选择加密整个连接字符串。您的服务应该能够解密并读取凭据/连接字符串,并将此信息传递给 sql 连接。
You would need to create a SQL login for this service (http://msdn.microsoft.com/en-us/library/aa337562.aspx). The username / password for this SQL login will need to be stored somewhere (app config/ registry) that the service can access.
Any time you store credentials, encrypt it so that no one else can see this in clear text. You could also choose to encrypt the entire connection string. Your service should be able to decrypt and read the credentials/connection string and pass this information to the sql connection.
您应该在服务器中将用户/服务名称添加为具有正确权限的用户,并且在数据库上添加相同的用户/服务名称,您可以使用 sql server managment studio 来执行此操作。
首先连接到服务器并在服务器用户文件夹中添加用户/服务,并将用户添加到数据库中的用户文件夹中。
看一下这篇文章,在页面末尾,它讨论了“授予对本地 SQL Server 的访问权限”
You should add the user/service name as User in the server with the right privilegies and the same on the database, you can do this with the sql server managment studio.
First Connect to the server and add the user/service on server users folder and the add the user to the user folder in the database.
take a look a this post, at the end of the page when it talks about "Granting Access to a Local SQL Server"
http://msdn.microsoft.com/en-us/library/ff647402.aspx
是的,如果您想使用特定的用户名和密码连接到 SQL Server,则需要在连接字符串中提供这些凭据。
是的,以纯文本形式存储它们是一件有点冒险的事情......
...幸运的是,.NET 允许您对配置文件的整个部分进行强力加密!
阅读在 .NET 应用程序中加密密码,与普遍看法相反,这在所有 .NET 中都可用 - 而不仅仅是 ASP.NET。它也适用于服务 - 根本不是问题。
因此,将 SQL Server 连接字符串存储到服务的
app.config
中,然后加密
部分即可完成!Yes, if you want to connect to SQL Server using a specific username and password, those credentials need to be provided in the connection string.
And yes, storing them in plain text is a bit of a risky business.....
... fortunately, .NET allows you to strongly encrypt entire sections of your config files!
Read about Encrypting Passwords in a .NET application, and contrary to popular belief, this is available in all of .NET - not just in ASP.NET. It works in services, too - not a problem at all.
So store your SQL Server connection string into the
app.config
for your service and then encrypt the<connectionStrings>
section and be done with it!