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:
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:
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.
P SilvaPosted Jul 15, 2013, 6:38 PM
So, I went to Visual Studio, and in the Server Explorer tab, I created a new Data Connection and was able to open the tables as it was supposed to be, without any problem regarding the login.
Then I copied the connection string it generated, and replaced it in the Web.config file, and when I tried to login in the web site, instead of the "Login failed for 'MyPCName\UserName'" exception, I'm getting a message that says "Format of the initialization string does not conform to specification starting at index 0."
I've been searching about it, and most of the sites mention that the cause for this error is probably the usage of quotes when we weren't supposed to use them, for example (the example is for VB.NET):
Dim myConn As New SqlConnection("strConnectionString")
Instead of
Dim myConn As New SqlConnection(strConnectionString)
The thing is I'm not using any declaraction of connection strings in my code as I'm using DataSets.
P SilvaPosted Jul 5, 2013, 6:19 PM
Also, I've tried using the sqlcmd utility, and I was able to connect to the server and execute queries through the command line, using Windows Authentication.
When I executed the SQL statement "SELECT CURRENT_USER" it returned dbo (as I'm the owner of that database), which is mapped to my Windows Login in the Security tab on the server node level.
I don't think so, but could a reinstall of SQL Server, in some way, be able to solve this problem?
Sunny SharmaPosted Jul 5, 2013, 3:44 AM
can you check for your connection string then? because if you're able to connect it through SSMS using user name and password then it must work.
P SilvaPosted Jul 4, 2013, 6:17 PM
Thanks for your answer.
The problem here is that when I attached the database to SQL Server through SQL Server Management Studio, and changed the connection string, I was unable to connect and that error "Login failed for user '...' failed." occured.
As mentioned before, I have a login for my Windows user in the SQL Server Management Studio, and the dbo user in the ASPNETDB database is mapped to the login mentioned.
What I don't understand is if it is possible that I've made any configuration in the SQL Server Management Studio so that it doesn't accept remote connections (although I've checked in the "Server Properties > Connections" tab, and the "Allow remote connections to this server" option is checked). or some other thing?
Sunny SharmaPosted Jul 4, 2013, 2:48 AM
Few things are there you need to do before going all the way.
First thing is to have a database on your SQL Server (that you already have).
Second is to create all the tables, stored procedures, views etc that are essential for AspNetSqlMembershipProvider. To do so, use "aspnet_regsql.exe". You will find this tool inside "%windir%\Microsoft.NET\Framework\v4.0.30319\"
Run this tool with admin previledges, click Next > select "Configure SQL server for application services > Next > put server path like ".\SQLEXPRESS" (Path of your SQL Server Instance) and other credentials and select a db from available list. and click Next > Next. This will create all the db components on selected database. Now you can use the database for AspNetSqlMembershipProvider.
Well, That was how to use ASP Membership Provider using SQL Server database. Coming to the point of your problem, If your database is local you can use Windows Authentication to get it working. Use a connection string like this:
"Server=.\SQLEXPRESS; Database=myDB; Integrated Security=true;"
That's all I think would get you out of the trouble. Happy coding :)
Mark it as answer if it helps.
Cheers!