Can't connect to Sql Server - asp.net

Im getting this error on the production server:
A network-related or instance-specific error occurred while establishing a > connection to SQL Server.
It's on IIS, and connecting to sql server with Windows authentication.
Any idea? or solutions?

The error message listed in the question typically occurs to me when I'm having connection issues, not related to credentials. Is your connection string setup properly? Have you tested it out on a different machine?
Additionally though, with windows authentiation in place, updated the web.config to set:
<identity impersonate="true"/>
solves the issue since the web application impersonates the person using the application, and their credentials have already been verified and are passed on to SQL Server.

Are you sure the production server has access to the relevant SQL Server? You can easily use the ODBC Data Source Administrator to test that this is so.

if it is a web application and you do not use impersonation, the application will try to connect with the IIS user, most likely NETWORK SERVICE, b/c that is the user that is running the app. My suggestion is to either use impersonation (see Dillie's post) or create an application user name and password and use that. I personally prefer application user names for most cases.

Related

Login failed for user '' IIS

Im currently trying to deploy my .NET MVC Application to IIS 7.5.
There is a database connection problem that im trying to figure out. In localhost, everything seems fine, however, when I deploy my app to remote server, the app runs, without connecting to database. For example I have a VisualLeadController that has getMonthlyLeadsByYear() method that connects to database and retyrns data. When I try to execute it from brower by typing
http://staging2.landornet.com/WebLeadsVisualizer/VisualLead/getMonthlyLeadsByYear
It generates this error:
Exception Details: System.Data.SqlClient.SqlException: Login failed for user ''.
The steps that I followed:
1-Removed integrated security=True from WebConfig connection strings
2- Changed applicationpool identity from applicationPoolIdentity to local system.
Still now working... anyone has any idea?
When deploying your web app to your remote server, you will need to use a SQL connection string that contains an explicit username and password associated with a SQL account. For example,
Data Source=SERVER;Initial Catalog=DATABASENAME;User ID=SQLUSERNAME;Password=SQLUSERPASSWORD
To use this connection string, you will need to first use SQL Management Studio to create a SQL login with a username and password, and give that user access to your database. Then log out out of SQL Management Studio and log back in using that user/password to make sure that it correctly can access your database. Hopefully then your web app should be able to connect to the database.

Having problems with aspnetsqlmembershipprovider

I have developed in asp.net for years and usually set up membership and roles in the same sql server database I use for cms. However, because I only need to password protect a couple of admin pages in my current project, I thought I would try the built in Account folder setup that Microsoft includes in its website template. So far it's been a nightmare.
I have the login working on my local machine, but when I uploaded to the server, I get the following error:
" A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)" The connection string provided by Microsoft says instance = true.
GoDaddy, the hosting provider, responded to my request to see if they could correct the connection string, by saying that the MDF file in the App_Data folder would only work on a dedicated server. (I'm skeptical...)
Making things even more challenging, I can open the sql express (.mdf) database and see the account I set up using the registration form. But when I try to test the default aspnetsqlmembershipprovider with the web configuration page inside my ap, I get a message saying:
Could not establish a connection to the database.
If you have not yet created the SQL Server database, exit the Web Site Administration tool, use the aspnet_regsql command-line utility to create and configure the database, and then return to this tool to set the provider.
I would really appreciate help in understanding what is happening so, if there isn't a duh solution, I can at least dismantle this thing in an intelligent way and then set up authentication in the webconfig, which would have taken ten minutes.
Many thanks.
Godaddy is wrong. Put your connection here and take a look at it for you. Remember to remove your login id and pwd in the connection string.

Why is this Asp.Net program signing into SQL as the current user?

A client of mine is using some older software I had written on a newer server setup. Despite having a connectionstring declared in the web.config file, the program keeps trying to log in as the current user and dumping out the error:
Login failed for user 'DOMAIN\currentUserJimbo'
Any ideas what would be causing this?
Their setup
Windows Server 2008
IIS 7
MSSQL 2005
If you have integrated authentication in the connection string and have enabled impersonation you should see that behaviour.
Integrated authentication will cause the web site to log on to the SQL server using the thread's current principal. When enabling impersonation, the thread will take the identity of the client. This can be useful if the web server is to access files or other resources on behalf of the user.
Maybe SQL Server authentication is turned off? And it connects using Windows Authentication?
Check to make sure the connection string being used doesn't have Integrated Security=SSPI; in it.
Check out these connection strings for some tips.

ASP.NET accessing a SQL Server in a different server

I have installed a new web application that access a SQL Server database in a different server. I'm using Windows Authentication and get the error of:
Login Failed for user XXX
When I try to set identity impersonate="true" in the web.config file, it just throws an error
Login Failed for anonymous user
Also, I'm using forms authentication to validate users from my website and using a different application pool.
Update: connection string Basically like this:
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;
Update:
My Virtual Directory has Anonymous Authentication and Windows Authentication enabled.
Typically ASP.NET runs as an anonomous account. In order to access a remote SQL Server using integrated authentication (SSPI), you'll need to have a bit more "permenant" presence. Easy way would be to shift the app pool to use the NETWORK SERVICE built-in account. Slightly trickier would be to use a named account. On the SQL server side of the equation you will need to give the same account -- either matching user/pass or NETWORK SERVICE -- proper permissions to your database.
Your DBA should be able to help.
It is difficult to provide you with an exact answer because you have not provided your connection string or info on your SQL Server config. Your best bet is to look at the IIS configuration and work out what user is attempting to access the different SQL Server. You then need to give this account access to the database. This is a common problem and most of the changes need to happen in SQL Server unless you can change the account that the web server is running under.

SQL Server SMO on IIS with Windows Auth

I'm getting a strange error when I enable windows authentication on IIS and try to run some database update scripts:
Invalid token for impersonation - it
cannot be duplicated.
I have not enabled any explicit impersonation.
I have narrowed it down to being something to do with SMO as when I change to a normal SqlClient and use ExecuteNonQuery, the problem goes away. This unfortunately is not a long term solution as the update scripts must be able to contain the 'GO' keyword which is not recognized by the standard SqlClient.
IIS worker processes are running as some user. When you use windows authentication, you are implicitly doing impersonation to the that user.
If your SQL server is on a different host, this probably isn't good enough. The impersonated user I think can only access local resources.
http://msdn.microsoft.com/en-us/library/ff647405.aspx#paght000025_usingimpersonation
Is SQL Server using windows authentication?

Resources