danielj Posted July 26, 2013 Share Posted July 26, 2013 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 More sharing options...
justsomeguy Posted July 26, 2013 Share Posted July 26, 2013 Does it actually say "domainservername$" or did you replace the actual names? Link to comment Share on other sites More sharing options...
danielj Posted July 26, 2013 Author Share Posted July 26, 2013 (edited) I replaced the actual names. The $ is after the name though. Edited July 26, 2013 by danielj Link to comment Share on other sites More sharing options...
justsomeguy Posted July 26, 2013 Share Posted July 26, 2013 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? Link to comment Share on other sites More sharing options...
danielj Posted July 26, 2013 Author Share Posted July 26, 2013 (edited) 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 July 26, 2013 by danielj Link to comment Share on other sites More sharing options...
justsomeguy Posted July 26, 2013 Share Posted July 26, 2013 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 More sharing options...
danielj Posted July 26, 2013 Author Share Posted July 26, 2013 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 More sharing options...
justsomeguy Posted July 26, 2013 Share Posted July 26, 2013 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. Link to comment Share on other sites More sharing options...
danielj Posted July 26, 2013 Author Share Posted July 26, 2013 (edited) Edit: I got it to work print and it prints what I put in the connection string. Edited July 26, 2013 by danielj Link to comment Share on other sites More sharing options...
justsomeguy Posted July 26, 2013 Share Posted July 26, 2013 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 Link to comment Share on other sites More sharing options...
danielj Posted August 2, 2013 Author Share Posted August 2, 2013 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 More sharing options...
justsomeguy Posted August 2, 2013 Share Posted August 2, 2013 Yeah, it sounds like it connects as the Network Service user, not the user you specify. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now