Jump to content

Insert Error: Login failed for user


danielj

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
Link to comment
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
Link to comment
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.

Link to comment
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.

Link to comment
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).

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...