Resolve “Login failed for user ''. The user is not associated with a trusted SQL Server connection.” in IIS within Windows XP

时间:2021-12-17 01:58:20

I'm getting the following error in my ASP.NET web application in IIS when running in Windows XP. I'm using Windows Authentication within the web application. I would normally use SQL Server Authentication (with mixed mode), but I do not have access to this database server, except read permissions. They only allow Trusted Connections (or Integrated Security=SSPI;) meaning using our Windows network authentication user.

在Windows XP中运行时,我在IIS中的ASP.NET Web应用程序中收到以下错误。我在Web应用程序中使用Windows身份验证。我通常会使用SQL Server身份验证(使用混合模式),但除了读取权限之外,我无权访问此数据库服务器。它们仅允许使用我们的Windows网络身份验证用户的Trusted Connections(或Integrated Security = SSPI;)。

Error:

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

.NET Code:

SqlConnection conn = new SqlConnection(
    "server=server_name;" +
    "Integrated Security=SSPI;" +
    "database=db_name;" +
    "connection timeout=30;");
SqlDataReader rdr = null;
List<Ticket> list = new List<Ticket>();

try
{
    conn.Open();
    SqlCommand cmd = new SqlCommand("SELECT TOP 10 [HEATSeq],[AssignedBy] FROM [dbo].[Asgnmnt]", conn);
    rdr = cmd.ExecuteReader();
    while (rdr.Read())
    {
        Ticket record = new Ticket();

        record.ticket_id = rdr[0].ToString();
        record.assigned_by = rdr[1].ToString();
    }
}
catch (Exception e)
{
    string x = "";
}
finally
{
    if (rdr != null)
    {
        rdr.Close();
    }
    if (conn != null)
    {
        conn.Close();
    }
}

It's the same type of issue that I answered in Jon Skeet's first question here. In Windows 7, you'd normally set the application pool to run using LOCAL MACHINE or NETWORK SERVICE (if you choose not to use SQL Server Authentication). Except I don't know where to change the user of the application pool in IIS 6.

这是我在Jon Skeet的第一个问题中回答的同类问题。在Windows 7中,您通常将应用程序池设置为使用LOCAL MACHINE或NETWORK SERVICE运行(如果您选择不使用SQL Server身份验证)。除了我不知道在IIS 6中更改应用程序池的用户的位置。

User permission error when accessing "user instance" database from ASP.NET

从ASP.NET访问“用户实例”数据库时出现用户权限错误

I read this article, but this applies to IIS in Windows 7, not Windows XP. How can I resolve this in Windows XP. Note that when I run this code in a console application, it connects fine.

我读过这篇文章,但这适用于Windows 7中的IIS,而不适用于Windows XP。如何在Windows XP中解决此问题。请注意,当我在控制台应用程序中运行此代码时,它连接正常。

http://blogs.msdn.com/b/sql_protocols/archive/2008/05/03/understanding-the-error-message-login-failed-for-user-the-user-is-not-associated-with-a-trusted-sql-server-connection.aspx

3 个解决方案

#1


0  

Under ApplicationPools right click on the pool that is used by your site. Choose properties, then go to the "Identity" tab. Click on the configurable radio button and type in the credentials. If you do not have a user to use then go to the link I provided it will give you steps to create your user.

在ApplicationPools下,右键单击您站点使用的池。选择属性,然后转到“身份”选项卡。单击可配置单选按钮并键入凭据。如果您没有用户可以使用,请转到我提供的链接,它将为您提供创建用户的步骤。

Custom Identity

#2


0  

Found the answer in MSDN.

在MSDN中找到答案。

http://msdn.microsoft.com/en-us/library/ab4e6cky(v=vs.80).aspx

In case the URL changes in the future, I'm pasting the text below from the documentation above. Fickle's answer is correct if dealing with Windows 7. From what I'm reading, you must give privileges to your computer's machine (running IIS in Windows XP) on the remote machine running SQL Server. I found it easier to just ask the DBA of SQL Server to create an account for me to log in via SQL Server authentication.

如果URL将来发生变化,我会从上面的文档中粘贴下面的文本。如果处理Windows 7,Fickle的答案是正确的。从我正在阅读的内容来看,您必须在运行SQL Server的远程计算机上为计算机的计算机(在Windows XP中运行IIS)授予权限。我发现更容易让SQL Server的DBA为我创建一个帐户,通过SQL Server身份验证登录。

=====================

This error can take a variety of forms, including:

此错误可以采用多种形式,包括:

Login failed for user '(null)'

用户'(null)'登录失败

Login failed for user domain\username

用户域\用户名登录失败

Login failed for user computer\ASPNET

用户计算机\ ASPNET登录失败

The likely cause is that you are working with a Web application and are trying to access a computer running Microsoft SQL Server. The specific error or exception that is raised depends on whether the Web server is also running SQL Server. This problem arises because the Web application is not passing valid credentials to SQL Server. In general, you can resolve this issue by doing the one of the following:

可能的原因是您正在使用Web应用程序并且正在尝试访问运行Microsoft SQL Server的计算机。引发的特定错误或异常取决于Web服务器是否也在运行SQL Server。出现此问题的原因是Web应用程序未将有效凭据传递给SQL Server。通常,您可以通过执行以下操作之一来解决此问题:

  • If the Web server is also running SQL Server, give the local ASPNET user login privileges (Windows 2000 and Windows XP) or give the NT AUTHORITY\NETWORK SERVICE login privileges (Windows Server 2003) on the server.

    如果Web服务器也在运行SQL Server,请授予本地ASPNET用户登录权限(Windows 2000和Windows XP)或在服务器上授予NT AUTHORITY \ NETWORK SERVICE登录权限(Windows Server 2003)。

  • If SQL Server is running on a remote computer and the Web server is running IIS 6.0, give the Web server's machine account login privileges on the remote computer. The machine account is referenced as DOMAIN\MACHINENAME$.

    如果SQL Server在远程计算机上运行且Web服务器正在运行IIS 6.0,请在远程计算机上授予Web服务器的计算机帐户登录权限。计算机帐户被引用为DOMAIN \ MACHINENAME $。

  • Set up ASP.NET to run as a Windows domain user who has login privileges on the computer running SQL Server.

    将ASP.NET设置为在运行SQL Server的计算机上具有登录权限的Windows域用户运行。

  • Use a connection string to use SQL Server standard security. To do this, you must configure the connection string with an explicit user ID and password.

    使用连接字符串来使用SQL Server标准安全性。为此,您必须使用显式用户ID和密码配置连接字符串。

For more information, see Accessing SQL Server from a Web Application.

有关更多信息,请参阅从Web应用程序访问SQL Server。

#3


0  

I was facing same issue while running my MVC application. I was getting error while connecting entity database on remote machine from MVC application as i was logged in by my window credentials.

我在运行MVC应用程序时遇到了同样的问题。我在远程机器上连接实体数据库时从MVC应用程序收到错误,因为我是通过我的窗口凭据登录的。

After using below batch script i got logged in by remote machine credentials so that issue resolved and application successfully connected to database.

使用下面的批处理脚本后,我通过远程计算机凭据登录,以便解决问题并将应用程序成功连接到数据库。

runas /user:corp\username /netonly "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe"

runas / user:corp \ username / netonly“C:\ Program Files(x86)\ Microsoft Visual Studio 11.0 \ Common7 \ IDE \ devenv.exe”

Please replace username with your corp username. It will prompt you command prompt, insert your password (Password will not visible). so that new instance will open for .net application which will be connected you by corp credentials

请用您的corp用户名替换用户名。它会提示您命令提示符,输入您的密码(密码将不可见)。这样新的实例将打开.net应用程序,它将通过corp凭证连接到你

#1


0  

Under ApplicationPools right click on the pool that is used by your site. Choose properties, then go to the "Identity" tab. Click on the configurable radio button and type in the credentials. If you do not have a user to use then go to the link I provided it will give you steps to create your user.

在ApplicationPools下,右键单击您站点使用的池。选择属性,然后转到“身份”选项卡。单击可配置单选按钮并键入凭据。如果您没有用户可以使用,请转到我提供的链接,它将为您提供创建用户的步骤。

Custom Identity

#2


0  

Found the answer in MSDN.

在MSDN中找到答案。

http://msdn.microsoft.com/en-us/library/ab4e6cky(v=vs.80).aspx

In case the URL changes in the future, I'm pasting the text below from the documentation above. Fickle's answer is correct if dealing with Windows 7. From what I'm reading, you must give privileges to your computer's machine (running IIS in Windows XP) on the remote machine running SQL Server. I found it easier to just ask the DBA of SQL Server to create an account for me to log in via SQL Server authentication.

如果URL将来发生变化,我会从上面的文档中粘贴下面的文本。如果处理Windows 7,Fickle的答案是正确的。从我正在阅读的内容来看,您必须在运行SQL Server的远程计算机上为计算机的计算机(在Windows XP中运行IIS)授予权限。我发现更容易让SQL Server的DBA为我创建一个帐户,通过SQL Server身份验证登录。

=====================

This error can take a variety of forms, including:

此错误可以采用多种形式,包括:

Login failed for user '(null)'

用户'(null)'登录失败

Login failed for user domain\username

用户域\用户名登录失败

Login failed for user computer\ASPNET

用户计算机\ ASPNET登录失败

The likely cause is that you are working with a Web application and are trying to access a computer running Microsoft SQL Server. The specific error or exception that is raised depends on whether the Web server is also running SQL Server. This problem arises because the Web application is not passing valid credentials to SQL Server. In general, you can resolve this issue by doing the one of the following:

可能的原因是您正在使用Web应用程序并且正在尝试访问运行Microsoft SQL Server的计算机。引发的特定错误或异常取决于Web服务器是否也在运行SQL Server。出现此问题的原因是Web应用程序未将有效凭据传递给SQL Server。通常,您可以通过执行以下操作之一来解决此问题:

  • If the Web server is also running SQL Server, give the local ASPNET user login privileges (Windows 2000 and Windows XP) or give the NT AUTHORITY\NETWORK SERVICE login privileges (Windows Server 2003) on the server.

    如果Web服务器也在运行SQL Server,请授予本地ASPNET用户登录权限(Windows 2000和Windows XP)或在服务器上授予NT AUTHORITY \ NETWORK SERVICE登录权限(Windows Server 2003)。

  • If SQL Server is running on a remote computer and the Web server is running IIS 6.0, give the Web server's machine account login privileges on the remote computer. The machine account is referenced as DOMAIN\MACHINENAME$.

    如果SQL Server在远程计算机上运行且Web服务器正在运行IIS 6.0,请在远程计算机上授予Web服务器的计算机帐户登录权限。计算机帐户被引用为DOMAIN \ MACHINENAME $。

  • Set up ASP.NET to run as a Windows domain user who has login privileges on the computer running SQL Server.

    将ASP.NET设置为在运行SQL Server的计算机上具有登录权限的Windows域用户运行。

  • Use a connection string to use SQL Server standard security. To do this, you must configure the connection string with an explicit user ID and password.

    使用连接字符串来使用SQL Server标准安全性。为此,您必须使用显式用户ID和密码配置连接字符串。

For more information, see Accessing SQL Server from a Web Application.

有关更多信息,请参阅从Web应用程序访问SQL Server。

#3


0  

I was facing same issue while running my MVC application. I was getting error while connecting entity database on remote machine from MVC application as i was logged in by my window credentials.

我在运行MVC应用程序时遇到了同样的问题。我在远程机器上连接实体数据库时从MVC应用程序收到错误,因为我是通过我的窗口凭据登录的。

After using below batch script i got logged in by remote machine credentials so that issue resolved and application successfully connected to database.

使用下面的批处理脚本后,我通过远程计算机凭据登录,以便解决问题并将应用程序成功连接到数据库。

runas /user:corp\username /netonly "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe"

runas / user:corp \ username / netonly“C:\ Program Files(x86)\ Microsoft Visual Studio 11.0 \ Common7 \ IDE \ devenv.exe”

Please replace username with your corp username. It will prompt you command prompt, insert your password (Password will not visible). so that new instance will open for .net application which will be connected you by corp credentials

请用您的corp用户名替换用户名。它会提示您命令提示符,输入您的密码(密码将不可见)。这样新的实例将打开.net应用程序,它将通过corp凭证连接到你