Wednesday, March 28, 2012

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

Hi all,

Can someone explain it to me why I am getting the following error when I try to connect SQL server express with .NET 2.0?

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Login failed for user ''. The user is not associated with a trusted SQL Server connection.

Here is my code and i am using windows authentication:

<%@. Import Namespace="System.Data" %>
<%@. Import Namespace="System.Data.SqlClient" %>

<%

Dim connAkaki As SqlConnection
Dim cmdSelectAuthers As SqlCommand
Dim dtrAuthers As SqlDataReader

connAkaki = New SqlConnection("Server=.\SQLEXPRESS;database=akaki")

connAkaki.Open()

cmdSelectAuthers = New SqlCommand("select Firstname from UserTableTest", connAkaki)
dtrAuthers= cmdSelectAuthers.ExecuteReader()

While dtrAuthers.Read()
Response.Write("<li>")
Response.Write(dtrAuthers("Firstname"))

End While

dtrAuthers.Close()
connAkaki.Close()

%>

Have you added the ASP.Net service account as a user in SQL Server? The error message is saying that the current user that is trying to connect has not been registered as a login in SQL Server.|||Hi there,

I was going to reply to your earlier post on the same/similar topic but since this one's newer I will post here.

The username with which the ASP.NET web application runs is different to the username you used to log into the computer with so chances are that the user is not defined in SQL Server's list of logins and so you get problems when using Windows Authentication.

A way around this is to use SQL Server authentication when trying to access your SQL Server. If you do this, your connection string will be:

connAkai = new System.Data.SqlClient.SqlConnection("Server=.\\NATHAN;database=Northwind; User ID=<SQL Server Login>; Password=<Password For Login>");

In a production system you would probably do more to secure that password (i.e. don't place it plain-text in the code) like putting it in the registry or some other methods but as an example I think it will do.

Hope that helps a bit, but sorry if it doesn't

|||

The SQL Server system by default is set to use only Windows Accounts and not SQL Server authentication, you can turn it on but I would leave it as is and use the windows accounts.

With ASP.Net generally the asp.net system by default runs under the Network Service account, to use it in the database you will need to make sure that the Network Service account has permissions for the database that you are using.

Another option is to make the asp.net application that you are working use a different account, this will help to secure your application. One way to do this is to reconfigure the application pool for the asp.net application that you have and make it run under the new account.

|||

Hi All!

How can add the ASP.Net service account as a user in SQL Server 2005?

|||

Huh? An MS Knowledge base article (http://support.microsoft.com/kb/555332) says just the opposite:

RESOLUTION

Change the Authentication Mode of the SQL server from "Windows Authentication Mode (Windows Authentication)"
to "Mixed Mode (Windows Authentication and SQL Server Authentication)".

|||

Steps to change SQLExpress to "SQL Server and Windows Authentication Mode"

If you are lucky to have Microsoft SQL server Management Studio installed, then can browse to the SQL server Instance and right-click to bring up the Server Property. Server Property -> Security -> check "SQL Server and Windows Authentication Mode" option under "Server Authentication" section, and then restart the SQLExpress.

If you don't have Microsoft SQL server Management Studio installed, the if you are running on XP Professional, following SQL statements will do the same:

You have to first login to SQLExpress using osql utility.

USE [master]

GO

EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'LoginMode', REG_DWORD, 2

GO

Hope that will help.

Derek

|||

Hey Glen, I have the same problem only I can't get sqlexpress to allow me to logon in SQL Server Auth mode. I can't even logon using my server (in my house). It will let me log on in Windows Authentication but not SQL Server Authentication? I have nothing on this machine and I reininstalled SQL Express twice. I am the sole admin .

All I want to do is create a blank database (which I did) and log onto it. I watched video 7 on microsoft and opened my fireall udp and added me as doadmin. I added sqlbrowser.exe,sqlserver.exe and udp port 1434 for sql via web in windows firewall. I also opened port 1434 on my hardlinksys router which only has port 80 and 1434 udp opened. (Public Webserver not hacked yet). Eventually, I added all permissions for my self (admin). I right clicked on my new database ("WebWizforums") IE not real database name. I added permissions under my user name and granted all permissions.It's only my user name in permissions noone else. I'll tighten ship perms after I see that she works...

Forum software is what I want to try http://www.webwizguide.com/webwizforums/kb/sql_server_install.asp seems real easy but I can't figure it out? MS Access I knew inside and out but now ...no more MSDE or MSJet on Longhorn OS.

Can anyone explain this simple task "Clearly?" Pretend I have no idea what I'm doing .... Smile Thanks Gates for forcing my higher "edgeamycashun."

SQL Express for dummies!

Learning SQL is like filing tax returns...put it off to the last minute!

Mike C

|||

Ok, I triple checked everything then I rebooted....now it works? I guess start and stop will be learned as stupid sql tricks.

ok, I added the database tables with no problems however, I get this message when I log into the (ADMIN.asp) page

Server Error in Forum Application
An error has occurred while connecting to the database.
Please contact the forum administrator.

Support Error Code:- err_SQLServer_db_connection
File Name:- common.asp

Error details:-
Microsoft OLE DB Provider for SQL Server
Invalid connection string attribute

I searched for Common.asp and right clicked it. It has READ at min. So next is connection String?

I got yarn? but no connection.

Getting closer Watson.

Mike

No comments:

Post a Comment