2

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.

8
  • 1
    Are you running under IIS locally? Oct 17, 2012 at 20:42
  • I'm pretty new to programming so bear with me and my answer. I do have an instance of IIS 7 installed but whenever the error appears is when I Debug.
    – Jose
    Oct 17, 2012 at 20:53
  • One you don't need db_owner rights to insert a row. You don't want users creating new databases. In Visual Studio you are running under your login. In the browser you are running under the authority of the ASP.NET application. When you say you added a user - what user?
    – paparazzo
    Oct 17, 2012 at 20:57
  • Ah okay, you can check if you're running under IIS by right clicking on your project, navigating to properties, going to the Web tab, then under the Servers section see what is ticked. The reason I ask is that it sounds like it could be an issue with your account's permissions in that application pool in IIS. Oct 17, 2012 at 20:58
  • mattytommo: I could not find exactly what you asked for, but I do not believe I am running IIS on this particular project since when I right click I see an option of "Use IIS EXPRESS". (I right click, then properties but do not see a Web tab).
    – Jose
    Oct 17, 2012 at 21:06

2 Answers 2

1

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.

0

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.