Wednesday, March 7, 2012

data base access

Hi,
I have problem accessing my sqlDatabase via asp.net
When running a test application I get the following error message:

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 'P900\ASPNET'.

I know the connection to the db is ok since I can gain access from a simple console application.

Anybody knows what's wrong and how to fix it??
Many thanks,

Cat33Is your ASPNET user on machine P900 a user in the SQL Server you are trying to connect to?

If you are using integrated security, a console mode applicaiton might work because integrated security while you are running a console mode application uses YOUR security context. Running an ASP.NET application, you are using the ASP.NET users' security context (ASPNET by default).

You need to either add the ASPNET user to SQL Server or use a username and password.

Look at the different possible connection strings here:

www.connectionstrings.com|||Ok, thanks for quick response. I have one simple question however;
How do I add the ASPNET user to the SQL Server?
Thanks in advance,
Cat33|||Do you have Enterprise Manager? If so, Expand out the Security folder, and right click on Logins and add a new login.

If not, there is a command line tool called OSQL you can use. Find it and add the folder to the path, or from the folder where OSQL is, run the following:


osql -S servername\instancename -E -q
--Line numbers will appear
EXEC sp_grantlogin 'COMPUTERNAME\ASPNET'
go
use <databasename>
go
EXEC sp_grantdbaccess 'COMPUTERNAME\ASPNET'
go
EXEC sp_addrolemember 'db_owner', 'COMPUTERNAME\ASPNET'
go

|||Hi,
Sorry to have to plague you with this access question, but after having done what you said, using the osql-tool, nothing improved. I still get the same Error Message, wheré the line 299 is hightlighted. I'm running Framework 1.1 with IIS 5.1 on a XP Pro machine. I have earlier been able to access the database so I simply don't know what to do. I have seen to it that the ASPNET account has been added to the directories in question. What do I do now? Do you have any idea as to where the source to the error is?
Thanks again,
Catharina

Error Message:

Login failed for user 'P900\ASPNET'.
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 'P900\ASPNET'.

Source Error:

Line 294:
Line 295:cmd = new SqlCommand(sql, con);
Line 296:con.Open();
Line 297:
Line 298:bool doredirect = true;

Source File: c:\inetpub\wwwroot\webapperikspage\start\newuser.aspx.cs Line: 296

Stack Trace:

[SqlException: Login failed for user 'P900\ASPNET'.]
System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction)
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction)
System.Data.SqlClient.SqlConnection.Open()
WebAppEriksPage.start.NewUser.InsertUser() in c:\inetpub\wwwroot\webapperikspage\start\newuser.aspx.cs:296
WebAppEriksPage.start.NewUser.btnAccept_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\webapperikspage\start\newuser.aspx.cs:147
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()|||When you ran the script in the previous message, you did replace COMPUTERNAME with your computer's name (P900), correct? Were there any error messages when you ran those lines through OSQL?|||Hi,
this is what I wrote:
osql - S P900\NetSDK -E -q
1> EXEC sp_grantlogin 'P900\ASPNET'
2> go

1> use Northwind
2> go

1> EXEC sp_grantdbaccess 'P900\ASPNET'
2> go

1> EXEC sp_addrolemember 'db_owner', 'P900\ASPNET'
2>go

1>exit
and I got no error messages

/Catharina|||OK. Also, replace Northwind with the name of the database you want to use. Northwind is a sample database used for that script.|||Well, at this stage the Northwind database is the database I'm using since this is a test trial to see that things work, which they don't, and I can access that database via a console application and also a Windows application.
Any more leads?|||If you added the user to the database, and there were no errors, then I cannot think of anything else.

Can you show your exact connection string (it should not have any password in it, so you should be able to just cut and paste it). If you did have access to Enterprise Manager, I would suggest looking there to verify that the user is really there.|||

con = new SqlConnection("server= p900\\NetSDK; Trusted_Connection=yes; database= Northwind");
I don't have access to Enterprise Manager, can I verify via osql?
Cheers,
Catharina|||When you start OSQL, rather than


osql -S servername\instancename -E -q

Should be, in your case:


osql -S p900\NetSDK -E -q

I have always used Trusted_Connection=true rather than =yes, so I would try that.

No comments:

Post a Comment