5
Answers

Error accessing SQL Server through Visual Studio

P Silva

P Silva

11y
1.2k
1
Hi
I'm developing a ASP.NET Web Site, and I'm using the login control.
Once I drag-and-droppped the login control or accessed the ASP.NET Configuration website, a ASPNETDB.mdf was created and placed under the App_Data folder and then I started to be able to register and use the login control as expected.
Later on, I needed to switch the database to the SQL Server, through the SQL Management Studio, and then changed the connection string in my Web.config file to use the specific DB, on the server instead of the connection string that was previously defined to use the ASPNETDB.mdf placed under the App_Data, like this:
<add name="ASPNETDBConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;
Integrated Security=True;User Instance=True" 
providerName="System.Data.SqlClient" />

The problem is, once I changed the connection string I was unable to access the SQL Server, because of an exception that says:
Login failed for user 'MyPCName\MyUserName'.

After this I tried  to create a new login and user in the SQL Server Management Studio and tried to change the connection string to use that username to connect to the database, and it was successful, but, when I try to use the login control or a page where I display user's details (using the Membership or Profile classes) the same exception occurs.
My connection string is now like this:
<add name="ASPNETDBConnectionString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=ASPNETDB;User Id=MyDBLogin;Password=MyPassword"
providerName="System.Data.SqlClient" />

I've checked that the mentioned User Id exists in the "Security" > "Logins" tab in SQL Server Management Studio, and there's a user in the database mapped to that login.
While searching the web trying to solve this problem I found people saying that to solve this error, I could try to activate the "Named Pipes" and "TCP/IP" options, in the "SQL Server Configuration Manager" > "SQL Server Network Configuration" > "Protocols for SQL EXPRESS" and the "SQL Server Browser" under the tab "SQL Server Services", which was already activated or I activated back then.
After all this, I'm still getting the same error.
Answers (5)