远程数据库服务器的连接字符串

发布于 2024-07-26 00:35:12 字数 818 浏览 3 评论 0原文

我目前设置了 2 台服务器。 一个是运行 Win Server 08 的 Web 服务器,另一个是在 Win Server 08 上运行 SQL Server 08 的数据库服务器。

目前我已经进行了站点设置,以便它可以使用我使用创建的连接字符串来读取/写入数据库数据库名称、服务器 IP、数据库用户和数据库密码。 我创建的数据库用户在数据库中具有“公共”角色设置(不是数据库所有者),并且只能运行 exec 存储过程。 我的连接字符串当前如下所示:

<add name="SiteDBConn" connectionString="Server=IPOfServer;Database=DBname;User ID=userhere;Password=passhere;"/>

虽然这对我来说非常有效,但我想设置一个不包含任何用户名和密码的数据库连接字符串。 在我的一些其他服务器上,其中 SQL 服务器与 Web 文件驻留在同一服务器上,我能够使用受信任的连接并在我的数据库上使用内置的“网络服务”用户。 这让我可以运行一个没有用户名和密码的连接字符串,如下

<add name="SiteDBConn" connectionString="Server=localhost;Database=DBname;Trusted_Connection=Yes;"/>

所示:当使用 2 个不同的服务器时,是否有一种简单的方法可以在不硬编码用户名和密码的情况下实现与数据库的连接(如上面的连接字符串)? 我是否在浪费时间沿着这条路线走下去,因为我创建的数据库用户无论如何都只有执行权限?

感谢您对此的想法。

I have 2 servers setup at the moment. One is a web server running Win Server 08 and the other is a database server running SQL Server 08 on Win Server 08.

Currently I have my site setup so that it can read/write to the database by using a connection string I created with the database name, server ip, db user and db pwd. The db user I have created has a 'public' role setup in the database (not db owner) and can just run exec stored procedures. My the connection string currently looks like this:

<add name="SiteDBConn" connectionString="Server=IPOfServer;Database=DBname;User ID=userhere;Password=passhere;"/>

While this is working perfectly for me, I would like to setup a database connection string that did not contain any username and password. On some of my other servers, where SQL server resides on the same server as the web files, I am able to use a trusted connection and use the built in 'Network Service' user on my database. This lets me run a connection string with no username and password like so:

<add name="SiteDBConn" connectionString="Server=localhost;Database=DBname;Trusted_Connection=Yes;"/>

Is there an easy way to achieve a connection to the database without hardcoding a username and password - like the above connection string - when using 2 different servers? Am I wasting my time going down this route seeing as how the database user I created has only exec permissions anyways?

Thanks for your thoughts on this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

阿楠 2024-08-02 00:35:12

你没有浪费时间。 这是一个非常好的做法。 当您在不同的计算机上分离 IIS 和 SQL 时,有一些选项:

  • 在 IIS 机器和 SQL Server 上创建 asp.net 用户(最好使用相同的密码)
  • 使用模拟(更改站点运行的上下文)
  • 加密注册表 配置文件中的连接字符串,并忘记可信连接 (brrrr)
  • 将 asp.net 上下文切换为域用户
  • 在本机应用程序模式下使用 IIS6

You are not wasting your time. This is a very good practice. When you separate out IIS and SQL on separate machines, here are some options:

  • Create the asp.net user on both the IIS box and the SQL server (preferably with same password)
  • Use impersonation (change the context your site runs under)
  • Encrypt a connection string in the registry a config file and forget about trusted connections (brrrr)
  • Switch the asp.net context to be a domain user
  • Use IIS6 in native application mode
夜吻♂芭芘 2024-08-02 00:35:12

如果这 2 台服务器不在同一个 Windows 域中,则无法使用可信连接。

此外,必须将登录名创建为 Windows 身份验证,您不能将 SQL 身份验证登录名与受信任的连接一起使用。

否则,塔波里所说的一切。

If the 2 servers are not in the same Windows domain, you cannot use trusted connection.

Also, the login must be created as a Windows authentication, you can't use a SQL authentication login with a trusted connection.

Otherwise, everything Tapori said.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文