Reputation: 1140
My problem is the following. I have a website that I'm creating and wanting to use Forms Authentication on it. Everything is fine and perfect except now that I have added the possibility of saving users to a database. I have added the database to my AppData folder on visual studio (created one). But everytime a user tries to create a new account (on my website) I get an error that looks like this (in debugging):
Login failed for user 'DOMAIN\username'
My connection string is the following:
<connectionStrings>
<add name="SecurityConnectionString"
connectionString="Data Source=(computername)\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Security.mdf;Integrated Security=True;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
The weird thing is that I can connect to SQL Management Studio with my windows login no problems. I have tried creating a new user (in SQL) and using those credentials but still no luck (get errors with regards to user not being able to create a new db even though I have given the user db_owner rights). Any insight would be appreciated. Thanks in advance.
Specifically this is the error I get
[SqlException (0x80131904): Login failed for user 'DOMAIN\username'.]
UPDATE:
I found something out. Whenever I change "Windows Authentication" to "SQL Server Authentication" on SQL Server Management Studio, I can't login, even with the right password and username. This might (most likely) be the source of the problem I believe.
Upvotes: 2
Views: 2166
Reputation: 1140
I found the solution. Just needed to create a new user (under SQL Server Authentication) and then add admin rights to that user using my Windows Authentication credentials through SQL, meaning, I created an user and then gave that user admin rights. This seems simple enough, the problem I was encountering was the following:
To my understanding, if you have access to a SQL database (whatever authentication mode you use) and you have admin rights on that database, you can do whatever you wish to it. However, it seems that is not the case as my 'DOMAIN\username' credentials were not authenticated when using SQL Server Authentication, meaning, I did not have admin rights.
Anyways, after creating the new user, and modifying the connection string, I managed to be able to write/read/anything to the database.
I appreciate everybody's help on the issue. Thank you.
Upvotes: 1
Reputation: 400
In the connection string (computername)
should be localhost
or whatever your computer's name is. Unless you are currently using (computername)
as a place holder for this post.
Upvotes: 0