ASP.NET Membership DB connection - asp.net

I can neither login from my application nor connect using the wizard to my Membership Provider on my local machine. My other DBs can connect from my application just fine. My connection string is correct, it has not been changed (I was able to login using membership previously, this is a new issue).
I created a new App to see if it could be the config, threw a login on it and registered and ran into the same issue.
This is the error message I am getting: "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) "
Though my other DB can connect I still checked:
TCP/IP enabled
Multiple connections enabled
Firewall down
Correct instance of sql server being referred to in Machine config.
Also, my network service account has rights to the DB, but should there be an ASPNET user?
I can't think of a single thing I have changed to this machine since this was working previously.
Thank you.
EDIT DETAILS: There are no aliases, yet, but if my other connections are working that shouldn't be the issue. I understand these things can be wonky though, so that's something I'm going to try now. Thanks. I will also try and take a look at what's going on while trying to connect. Best way: event logs?
I am using Windows Auth, I'm connecting locally, using Windows 7 and SQL Server 2008 along with VS 2008. I can connect with Management Studio and query the DB, yes. NetworkService account has rights to the DB.

Check the Server name in the connection-string if the Sql-Server is in the same machine with the web application use "."(dot) without quotes instead of the computer-name in your connection string.

Have you tried sniffing it to see if there's anything you can see on the wire when the connection attempt is made?
Are there any aliases around the server/DB name? Have you tried creating one and connecting to it?
Are the other instances you can connect to on the same machine? Same SQL Server instance?
If you use impersonation, does the problem go away?

It sounds like you can connect to one database, but not the one you need. Is that correct?
The ASPNET user is a Windows XP thing. You should generally use NETWORK SERVICE for server-based deployments.
So, you can connect from Management Studio, but not from IIS? What identity are you using for the IIS AppPool?
Can you connect if you use Cassini (the web server that comes with Visual Studio)? That should pass through your user ID.

Related

Why is IIS7 blocked from accessing my database when connecting to a website via a browser from a client machine?

When I access the website from the same machine IIS is running on I am able to connect to the database, but not if I try to access it remotely. The only way I've managed to get it to connect is when I specify Physical Path Credentials:
click to open image
This doesn't work for me because, I am using the username as a search criteria when querying the database and this way I always get the same username (the one I specified in the physical path credentials).
I am confused because, when accessing the website locally and remotely I use the same credentials and I get different results.
This is the exception that is thrown when trying to access the site remotely:
ByNadexLoginSystem.Exception: System.Exception:
'SelectDataObject()' failed --->
System.Data.SqlClient.SqlException: 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: Named Pipes Provider, error: 40 -
Could not open a connection to SQL Server) --->
System.ComponentModel.Win32Exception: Access is denied --- End of
inner exception stack trace
I have tried adding folder permissions as pointed out here:
ASP.NET Application page not working on clients computers with no success whatsoever.
The SQL server is configured to allow remote connections.
I am sure it is a permissions problem I just can't find where. Any ideas?
I found the solution to my problem, I want to give credit to Sean Lange. Thanks to his question it gave me a line of investigation to follow. While going through msdns documentation here https://msdn.microsoft.com/en-us/library/bsz5788z.aspx I found this:
If SQL Server is on a different computer than the Web server, the
Windows identity must be able to flow across the network to the remote
instance of SQL Server. (Windows networks that have been configured
appropriately with Kerberos authentication are able to do this.)
However, depending on the settings in the identity configuration
element, the Windows identity established on the operating system
thread for ASP.NET applications may not be able to flow properly to
the remote SQL Server.
In IIS, only Basic Authentication logs users on with a security token
that flows across the network to a remote SQL server. By default,
other IIS security modes used in conjunction with the identity
configuration element settings will not result in a token that can
authenticate to a remote SQL Server.
Enabling Impersonation and Basic Authentication ( disabled Windows Authentication ) solved it!

SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. The specified LocalDB instance does not exist

EDIT: One important detail that I original left out (because I didn't know it was important) is that we were running these sites in full IIS, not from IIS Express.
We're trying to setup local dev environments for Kentico CMS that will add our local machines to our current synchronization chain of Dev --> Staging --> Prod (so we'll wind up with Locals --> Dev --> Staging --> Prod).
We copied our Dev DB to our local machines onto the (localdb)\v11.0 instance of SQL Server, but we're running into an issue on everyone's computers except mine.
Here's the error we're getting:
The application could not connect to the database, please check the
connection string in the web.config file and SQL server availability.
Original 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: 50 - Local Database Runtime error occurred.
The specified LocalDB instance does not exist. )
I've tried a ton of suggestions from other SO answers and other websites to figure out why we're getting this error (and why it's not happening on my machine), but no luck. We can connect to (localdb)\v11.0 in SSMS but we cannot connect to it through VS (same error). Also, when we open Sql Server Config Manager, we're not seeing any listings for SQL Server Services. Any ideas?
Make sure you have .NET Framework 4.0.2+ installed
Set up your AppPool to run under the NetworkService account.
Create a login for that account in your db.
USE [master];
CREATE LOGIN [NT AUTHORITY\NETWORK SERVICE] FROM WINDOWS;
EXEC sp_addsrvrolemember N'NT AUTHORITY\NETWORK SERVICE', SYSADMIN;
Share your instance with all users by running
SqlLocalDB share Kentico KenticoShared
Use connection string in the following format:
<add name="CMSConnectionString" connectionString="Data Source=(localdb)\.\KenticoShared;Initial Catalog=KenticoDB;Integrated Security=True;Connect Timeout=60" />
If it doesn't help use a named pipe:
<add key="CMSConnectionString" value="Persist Security Info=False;Integrated Security=SSPI;database=KenticoDB;server=np:\\.\pipe\LOCALDB#D2BA6590\tsql\query;Current Language=English;Connection Timeout=120;" />
Notes:
the exact name of the NetworkService account on your machine can be determined by running following C#
var ns = new SecurityIdentifier(WellKnownSidType.NetworkServiceSid, null).Translate(typeof(NTAccount)).ToString()
named pipe can be determined by running this in CMD: SqlLocalDB info KenticoShared
don't forget to run your instance SqlLocalDB start KenticoShared
Seems a little obscure, but have you looked at http://support.microsoft.com/kb/941823 , "Some or all SQL Server 2005 services are not listed in SQL Server Configuration Manager..."?
And there are generally two things that get in the way of connecting to SQL Server from an application even though you can connect using Management Studio. First, you should make sure that TCP is enabled on the instance, http://msdn.microsoft.com/en-us/library/bb909712(v=vs.90).aspx . Second, since you're connecting to a named instance, which I'm assuming is not the default instance running on the standard port, you need to make sure that the SQL Server Browser service is running, http://technet.microsoft.com/en-us/library/ms165734(v=sql.90).aspx . This is what redirects applications to a non standard port without having to specify the port directly. The reason Management Studio can get past these is that it can connect through named pipes and skip TCP altogether.
See this post as this solved my problem:
These two posts on Using LocalDB with Full IIS should give you more information. Especially the second part seems relevant, but the first one contains some context as well.
Part 1: User Profile
Part 2: Instance Ownership
Credit: IIS connecting to LocalDB

.NET server stopped working

I was developing, and recompiled started my website with ctrl+F5 and got 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)
How can this even happen?
I didn't changed anything.
I started empty MVC application and start it with CTRL+F5 and it works. I restart my main app, and still doesn't work. Damn.
Problem is, that I didn't change any connection string, anything in mssql server, didn't restart anything. I just compiled application like usual, and it said something about Antlr3 first, then couldn't connect to server anymore.. Changed the port for sql express and it started to work for a 20 minutes, and stopped working again.. don't understand.
this error threw for two type of problem .
1) Check your connection string for correct server Name and database Name ,etc..
Examble : Setting up connection string in ASP.NET to SQL SERVER
2) Check your sqlserver for open , if your sql server is there is any another system , please check your local network and another system network .
Please see this solution
Connect your SQL server from Visual studio > View > server Explorer,test and copy the connection string from there.It will work...My guess is you have a wrong connection string with wrong instance..
Is your database can be accessed outside the network. I think you need to add SQL server to firefall application to access it outside.
To add the sqlservr.exe to windows firefall
1. Go to Control Panel\System and Security\Windows Firewall\Allowed Programs.
2. Click Allow another Program.
3. Add SQL Server
Go to Control Panel -> Administrative Tools -> Services -> SQLServer . Check SQLServer to make sure it is started.
I forgot to put [InitializeMembership] attribute in my HomeController.cs, and it was looping forever because I was using RolesMembership ;)

Error connecting to SQL Server via alias from local IIS7

Just wondering if anyone has run into this before. Had a few devs look at this, and none of us can figure it out.
I have an ASP.NET Web Forms app connecting to a Sql Server db via an alias using EF4. The alias is set to point to my machine name (not "." or "local"). When I run it out of VS2012, it works fine. If I deploy it to my local instance of IIS7 and try to pull it up in a browser, I get the 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: Named
Pipes Provider, error: 40 - Could not open a connection to SQL Server)
My connection string looks like this:
Data Source=aliasName;Initial Catalog=databaseName;Integrated Security=True;MultipleActiveResultSets=True
If I change the connection string so that the Data Source is my machine name instead of the alias, it works fine from IIS7. So, the problem appears to be something with the alias and only when running out of IIS7.
As a workaround, I am using a local build profile to deploy a different web.config that doesn't use the alias locally, but I would really like to figure out why it's not working.
Any advice would be appreciated.
Check this, specifically:
Pre-requisites for SQL Server Alias usage
You must be willing for your clients to connect to the instance via a network protocol. It is not possible to use shared memory connections that are available when the client and instance are on the same system. I use TCP/IP connections for my aliases.
On the system hosting the SQL Server instance you must have the SQL Server Browser service running (this is normally has Start Mode set to Automatic).
On a 64-bit system, if you have both 32-bit and 64-bit clients, you will need to create an alias for BOTH 32-bit and 64-bit clients.

Not able to connect to the SQL Server data from asp.net app

We are upgrading from an environment where the development web server, the SQL Server 2005, and SQL Server data are all on the same machine, a Windows XP Machine. We are upgrading to having the web server on one Windows 2008 server, the SQL Server on a 2nd Windows 2008 Server, and to Server to a Windows 2008 server, nd the data on a SAN.
Now we are getting the error message:
A connection was succesfully established with the server, but then
an error occured during the login
process. (provider: named pipes
provider, error 0, no process is on
the other end of the pipe.)
The network guy thinks it is a problem with the connection string:
<add name="CNString"
connectionString="Data Source=WEBSERVER;
Initial Catalog=PCIdb;
User ID=sa;Password=pass;"
providerName="System.Data.SqlClient"/>
Can anyone help out here?
Is your SQL Server really called WEBSERVER (DataSource="WEBSERVER") ??
Also, I would never EVER use the sa account in a connection string - NEVER, period. Use an application specific user or something, but do not use the sa account under any circumstances.
This can be caused by any number of reasons, but the first thing to look at is the configuration and setup of the SQL Server itself.
Are named pipes enabled on the server? You can check this through the server configuration manager (on the SQL Server machine itself).
Is the user on the connection string (or the connection pool user if you are using SSPI) setup on the server?
Note:
I do hope the connection string you put up is an edited version of your real one, as there are a couple of issues with it:
Using the sa login - you should never do that as now any SQL exploit can do any damage it wants
Calling a sql server "webserver" - a really confusion naming decision
When it comes to connection strings, look at connectionstrings.com - they hold a good list of valid connection strings to many databases using different providers.
I got that error before...Make sure SQL server services are started
If that's not it, change the authentication mode to both server and windows.
It could be a connectionstring problem. Try comparing your connectionstring to the connectionstrings at http://www.connectionstrings.com but it could also be that the remote connection or the remote server (the webserver in this case) isn't allowed to connect to SQL.
Check if remote connections are allowed and named pipes and/or TCP/IP protocols are enabled on the database server.
But, based on the scenario you've described, I'd say it's the database-end that's refusing the connection (since you've already had a working solution).

Resources