coure2011 coure2011 - 2 months ago 11
ASP.NET (C#) Question

Cannot open database "test" requested by the login. The login failed. Login failed for user 'xyz\ASPNET'

I have created a webservice which is saving some data into to db. But i am getting this error


Cannot open database "test" requested
by the login. The login failed. Login
failed for user 'xyz\ASPNET'.


my connection string is


add name="ConnectionString1" connectionString="Data Source=.\SQLExpress;Initial Catalog=IFItest;Integrated Security=True" providerName="System.Data.SqlClient"

Answer

Well, the error is pretty clear, no? You are trying to connect to your SQL Server with user "xyz/ASPNET" - that's the account your ASP.NET app is running under.

This account is not allowed to connect to SQL Server - either create a login on SQL Server for that account, or then specify another valid SQL Server account in your connection string.

Can you show us your connection string (by updating your original question)?

UPDATE: ok, you're using integrated Windows authentication --> you need to create a SQL Server login for "xyz\ASPNET" on your SQL Server - or change your connection string to something like

connectionString="Servere=.\SQLExpress;Database=IFItest;User ID=xyz;pwd=top$secret"

if you have a user "xyz" with a password of "top$secret" in your database.