Jump to content
Sign in to follow this  
danielj

Insert Error: Login failed for user

Recommended Posts

I created an asp.net webform that submits to an sql database on an sql server. The web server is Windows server 2012. The page successfully submits when I run the page using Visual Studio 2012, but when I run it on the web server (not using Visual Studios) I get the error message below when I click submit. It says login failed for user domainservername$, but the username in the connection string is user we created for the sql database. It uses Windows Authentication.

 

I setup the web server for asp.net. I haven't done it before, so I assume the issue is there or in the connection string, though I'm not sure. The connection string is below. I'm new to asp.net, c#, and sql, so I'm learning as I go in this project.

 

Let me know if you need anymore information.

 

Thanks for any suggestions.

 

<connectionStrings>
<add name="MyConsString" connectionString="Server=sqlserver; Database=database; User Id=username; password=password;
Trusted_Connection=Yes;"
providerName="System.Data.SqlClient" />
</connectionStrings>
Server Error in '/' Application.
--------------------------------------------------------------------------------
Insert Error:Login failed for user 'domainservername$'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Exception: Insert Error:Login failed for user 'domainservername$'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[Exception: Insert Error:Login failed for user 'domainservername$'.]
Survey.WebForm1.ExecuteInsert(EventArgs e) in servernamec$inetpubSurvey2Surveydefault.aspx.cs:489
Survey.WebForm1.Button1_Click(Object sender, EventArgs e) in servernamec$inetpubSurvey2Surveydefault.aspx.cs:39
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +155
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3804

Share this post


Link to post
Share on other sites

If it's trying to authenticate with the server name, then it sounds like it isn't using the connection string with the username. How are you connecting to the database?

Share this post


Link to post
Share on other sites

I'm not sure if you are asking something else, but I'm connecting to it using the connection string. I haven't setup a connection to the database anywhere else.

 

Edit:

It had initially confused me since it appeared to be using the server's name to log in. I wasn't exactly sure if that was happening, but if it is, what could be causing that?

Edited by danielj

Share this post


Link to post
Share on other sites

If it's trying to use the server's name then it sounds like it doesn't find the connection string for whatever reason, or else I would think it would use the username in that connection string to log in. Where in the code are you using that connection string to connect to the database? If you're not using it, that might be the problem.

Share this post


Link to post
Share on other sites

The thing is, is that it works when I run the page using Visual Studios. The connection string is called when I click the submit button. The submit button calls Button1_Click which calls ExecuteInsert, which creates a SqlConnection variable. That variable calls GetConnectionString and that is where the connection string is used.

Share this post


Link to post
Share on other sites

I'm not sure what to say, maybe it would be good to try and print the connection string from the code to make sure it's getting the right one.

Share this post


Link to post
Share on other sites

It sounds like it's trying to connect as the network service user rather than the user in the connection string. Check here, there are some links to other solutions also:

 

http://stackoverflow.com/questions/2806438/login-failed-for-user-domain-machinename

Share this post


Link to post
Share on other sites

Thanks, those links helped. I got it working. I don't know if I understand it 100%, but the web server needed to be to added to the Security Logins in SQL (using the SQL management tool). The login made is domainservername$ ($ included).

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...