使用域用户的 SQL 连接字符串?

发布于 2025-01-06 23:45:10 字数 635 浏览 3 评论 0原文

以前,对于我们所有的 ASP.NET 应用程序,我们一直在 SQL Server 中使用 sysadmin 用户来连接和添加/更新/删除/获取数据。我们的 SQL 管理员想要删除该帐户并创建一个域帐户,以便我们可以在 .net 应用程序中使用该帐户。

我当前的连接字符串是:

name="name" connectionString="Data Source=server;Initial Catalog=database;Persist Security Info=True;User ID=user;Password=password" providerName="System.Data.SqlClient"

使用域帐户的连接字符串是什么?

我尝试过:

name="name" connectionString="Data Source=server;Initial Catalog=database;Persist Security Info=True;User ID=domain\user;Password=password" providerName="System.Data.SqlClient"

但不起作用。

是否有其他方法可以使用域帐户连接到 SQL Server?

Previously for all our asp.net applications we have been using a sysadmin user within SQL Server to connect and add/update/delete/get data. Our SQL Admin wants to delete that account and create a Domain Account so we can use that account within our .net applications.

My current connection string is:

name="name" connectionString="Data Source=server;Initial Catalog=database;Persist Security Info=True;User ID=user;Password=password" providerName="System.Data.SqlClient"

What would the connection string be for using a domain account?

I tried:

name="name" connectionString="Data Source=server;Initial Catalog=database;Persist Security Info=True;User ID=domain\user;Password=password" providerName="System.Data.SqlClient"

and it does not work.

Is there a different way to connect to SQL Server using a domain account?

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

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

发布评论

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

评论(6

唐婉 2025-01-13 23:45:10

查看 connectionstrings.com 了解每种可能的变化 - 我一直使用的非常方便的资源

具体来说,您想要这种格式:

Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;

当然,只有当相关域帐户是打开连接的帐户时,这种格式才有效。

没有简单的方法可以使用任意凭据进行连接 - 但您可以模拟有问题的用户,然后进行连接。

这可能有点痛苦。如果用户位于本地网络(或者您控制他们的浏览器配置),另一种选择是在您的站点上使用 Kerberos 身份验证。这些页面将具有相关用户的权限 - 然后您可以使用上面的连接字符串,IIS 将使用每个用户的适当凭据连接到数据库。从安全角度来看,这特别有用,因为数据库能够基于每个用户进行审核,并且权限可以是每个用户/行/列,而不仅仅是每个应用程序。

Have a look at connectionstrings.com for every possible variation - a very handy resource I use all the time

Specifically, you want this format:

Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;

This, of course, only works if the domain account in question is the one opening the connection.

There's no easy way to connect with arbitrary credentials - but you can impersonate the user in question and then connect.

This can be a bit of a pain. An alternative if the users are on the local network (or you control their browser config) is to use Kerberos authentication on your site. The pages will be served with the relevant user's permissions - then you can use the connection string above and IIS will connect to the Db with the appropriate credentials for each user. This is particularly useful from a security perspective as the Db is able to audit on a per-user basis, and permissions can be per-user/row/column instead of only per-app.

给妤﹃绝世温柔 2025-01-13 23:45:10

如果您想使用不同的用户帐户,那么登录用户有两个选择。

选项1

您可以将用户添加到应用程序池标识。

为此,请转到应用程序池的高级设置并编辑身份以使用您想要的用户。

选项2

在 Web 配置中添加此内容:

<identity impersonate="true" userName="Domain\User" password="Password" />

并使用此连接搅拌:

<add name="Name" connectionString="Data source=SqlServer;Initial Catalog=DbName;Integrated security=True" providerName="System.Data.SqlClient"/>

有关更多详细信息,请参阅:
https://msdn.microsoft.com/en-us/library/134ec8tc.aspx

还在这里找到了另一篇好文章
https://www.codeproject.com/tips/520341/implement -asp-net 中的模拟

If you want to use different user account then the logged in user you have two options.

Option 1

You can add the user to Application pool Identity.

For this go to advance setting of application pool and edit the identity to use the user you want.

Option 2

Add this in Web config:

<identity impersonate="true" userName="Domain\User" password="Password" />

And use this connection stirng:

<add name="Name" connectionString="Data source=SqlServer;Initial Catalog=DbName;Integrated security=True" providerName="System.Data.SqlClient"/>

For More Details See:
https://msdn.microsoft.com/en-us/library/134ec8tc.aspx

Also found another good article here
https://www.codeproject.com/tips/520341/implement-impersonation-in-asp-net

剩余の解释 2025-01-13 23:45:10

使用集成安全性:

Integrated Security=SSPI

有一个变体:

Trusted_Connection=True

不同的连接字符串(针对各种数据库)可以在 connectionstrings.com 上找到。

对于这两者,您需要确保应用程序在您需要登录的帐户下运行。

Use integrated security:

Integrated Security=SSPI

Which has a variant:

Trusted_Connection=True

The different connection strings (for a variety of databases) can be found on connectionstrings.com.

With both of these you need to ensure that the application is running under the account you need to login with.

苦行僧 2025-01-13 23:45:10

是的,试试这个:

Data Source=server;Initial Catalog=database;Integrated Security=SSPI;

这指定您希望使用集成的 Windows 身份验证,而您仍在尝试使用 SQL Server 身份验证(即使您输入的用户名看起来像 Windows 域/用户帐户,SQL Server 仍将其视为标准 SQL Server 身份验证) )

另请查看 connectionstrings.com

Yes, try this:

Data Source=server;Initial Catalog=database;Integrated Security=SSPI;

This specifies that you wish to use integrated Windows authentication where you were still trying to use SQL Server authentication (even though the username you entered looked like a Windows domain / user account SQL server still treats it as standard SQL Server authentication)

Also take a look at connectionstrings.com

司马昭之心 2025-01-13 23:45:10
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;

以上是针对 SQL Server 实例进行 Windows 身份验证的连接字符串。

Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;

The above is a connection string for Windows Authentication against your SQL Server instance.

俯瞰星空 2025-01-13 23:45:10

最近尝试使用 Invoke-Sqlcmd 通过 AAD 用户对 Azure Sql Server 进行身份验证时遇到了此问题。将身份验证方案添加到连接字符串中解决了这个问题。我怀疑此错误仅影响 SqlServer 模块 v21 及以下版本,因为我没有在本地计算机上使用 v22 获取它。

;身份验证=Active Directory 密码”

Ran into this issue just recently trying to auth to an Azure Sql Server with an AAD user using Invoke-Sqlcmd. Adding the auth scheme to the connection string resolved it. I suspect this bug only affects SqlServer module v21 and below as I was not getting it using v22 on my local machine.

"<ConnString>;Authentication=Active Directory Password"

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