can not connect to SQL database on amazon EC2 - microsoft project server database - asp.net

I am using SQL managment studio 2008 running on an Amazon EC2 machine. I am unable to connect to the database in my asp.net application. The EC2 instance has been set to accept connections over the SQL port. I am also able to remote the machine as well as view websites hosted on the server. Listed below is part of the connection string relating to this instance. When the program is ran and this connection string is called, it returns tcp error 0 - no return response. it just times out.
<add name="ProjectServer" connectionString="Data Source=*IP ADDRESS HERE*,1433;Initial Catalog=*Catalog Name*;User ID=IP-0A6ED514\Administrator;"/>
I removed the ip and the catalog name for the example, but I am sure they are correct.
The only thing that I could think may cause an error, is the differences in names between the user id and the server name - the server name is ip-0A6ED514\sharepoint but the user name is ip-0A6ED514\administrator when I log into the sql server manager on the EC2 instance. A password is not used. Not sure if I would need to leave in a blank string for password - also not sure if the difference between server name and user id to log in makes a difference. Any help is appreciated. Thank you.
update - when this connection string is used with out the port, i get tcp provider error 40 - when the port is in there, i get error 0
edit- the sql server is using windows authentication - does this make a difference? Usually I always use SQL server authentication
edit 2- now running sql express at same location, would i need a \SQLEXPRESS tag? I feel like after looking around and what could be the error, it is that I am reaching the machine ok, but its not pointing me to the DB, any suggestions?

Related

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

Could not open a connection to SQL Server

I have problems connecting to my database server. The database server is not local, I am connected via its IP address.
It works fine in my development machine. After publishing the website to my server, it can not connect to my database server.
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)
Why can't my publish server connect to the database server, whereas it works fine through the development machine?
I often had that problem. Mostly it's because of two problems.
Open the SQL Server Configuration Manager.
Check if the SQL Server Network Configuration supports TCP/IP, if it's disabled, enable it.
e.g. SqlServer 2005 Network Configuration, Protocols for SQLEXPRESS
Open the SQL Server Management Studio
Click on the Sql Server Properties (right click on the server name and
select properties).
After that, select the page "Security" and switch the check to "SQL Server and Windows Authentication mode".
That's all.
I'll attempt to go two for two on the psychic debugging for today...
I will assume that you are not using integrated security? If so it might explain things as the account on your local machine probably has permissions, but the SYSTEM account that is running on the server does not. Just a shot in the dark though.
It sounds like your server can't make the network connection, rather than a security issue.
Ensure that any firewalls on both the DB and app servers allow traffic on the port (1433).
Ensure you're able to ping or tracert from both machines.
Is it your first time you publish your website on the web server ? if it is , Are you sure you have set your connection string properly ?
You need to create a login ( of curse a password for that too ) and the IP Address of that SQL on the web server .
So you need IP Address of the sql server host , Database Name , UId , Pwd .
I will agree that this sounds like a network issue and not a security issue.
Remote into the web server and ping the DB server by IP address. If this does not work, your server cannot see the DB server via that address (different subnet, incorrect firewall/proxy setup, etc). There may be a proxy address you must use to get to the DB server from the web server, or your web server may also be the gateway and IIS doesn't know to look for the DB server on the LAN. If it does work, the computers may not be talking on the same port, or the firewall may be blocking that port exiting the web server.
I have spent hours trying to connect to SQL server using sqlcmd. I disabled my firewall, checked all ip listed in "Protocols for SQLEXPRESS", edited my hosts file. I tried using different ips and machinename to connect to the server. But none of work worked. After hours of investigation, I found out that I made absolutely stupid blunder making me unable to connect.
I want to remind people that the connection string is not case sensitive. But the option is!!
what i did is I put
sqlcmd -s .\sqlserver
But the correct string is
sqlcmd -S .\sqlserver
so watch out, people

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).

ASP.NET Membership DB connection

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.

SQL Server 2005 has problems connecting to a website running on the same server

An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Hello I am new on developing on SQL Server 2005. I've worked for several years with SQL Server 2000, but after doing the usual stuff I do to connect to the server I get this exception on the web server.
There are several links on google that point me to possible solutions, but none of them have solved my problem. I've made changes on a "Surface Area whatever..." dialog (What the hell is that??? Why does SQL Server has changed so much??? It seems so complicated now).
I have ensured that SQL Server 2005 is configured properly to allow incoming connections on the instance of database server. I also have selected Automatic as the Startup type to start SQL Server Browser service automatically every time system starts. And no, there is no firewall running.
I've tried changing the connection string to connect using a port, to connect using the IP, to connect using the instance name...
Nothing seems to work, I'm still getting the same error. Any hint?
Answering the questions that people have made:
Yes, I can connect using management studio from a different computer.
Yes, I'm sure it's configured to accept local and remote TCP/IP and named pipes.
Yes, I restarted the server.
I am using Mixed mode security, which I already enabled. I already enabled the sa user.
I am able to connect to the database using a .udl file, and I've checked that my connection string is OK. I can connect to the database using DBArtisan and SQL Server client tools. I can do that both on the server and on a different machine. Even with all that...
The website is still unable to connect.
New update...
I've been struggling all day with this problem, and still haven't found out the cause. It seems that the error message I posted is a generic error that .net gives when it's not able to connect. I placed trash on the connection string (typing servers that don't exist) and I still get the same error.
These are some of the connection strings I've used on the server:
connectionString="Integrated Security=SSPI; Data Source=SERVER; Initial Catalog=db; Network Library=DBMSSOCN;"
connectionString="Data Source=SERVER; Initial Catalog=db; User ID=sa; Password=xxxxx;"
connectionString="Data Source=SERVER\MSSQLSERVER; Initial Catalog=db; User ID=sa; Password=xxxxx;"
I tried to register the sql server instance using some strange command, I found that here:
http://kb.discountasp.net/article.aspx?id=1041
To do that I used the aspnet_regsql.exe tool. It's still not working...
I also know that the server has the latest version of MDAC installed on it. The only thing that I'm suspicious on is that the server has two Database engines: SERVER and server\sqlexpress
Does that has something to do with the problem?
The only thing that I'm suspicious on is that the server has two Database engines: SERVER and server\sqlexpress
I think this is the source of the problem. Which one do you intend to connect to? You need to specify the "instance" you are connecting to.
Assuming you intend to connect to the SERVER instance, you connection string should then look like this (assuming the default instance name):
Data Source=YOURSERVER\MSSQLSERVER; Initial Catalog=db; User ID=sa; Password=xxxxx;
Or for sql express the connection string looks like this:
Data Source=YOURSERVER\sqlexpress; Initial Catalog=db; User ID=sa; Password=xxxxx;
Can you connect to the SQL Server via Management Studio from a different machine? This might help you narrow down whether it is the SQL Server configuration or you connection string configuration.
Recheck the surface area configuration, and make sure TCP/IP connections are allowed.
This could be many things. The first thing I would check is to make sure you can connect to the server using SQL Server Management Studio. Second, check your connection string to make sure it is correct. Surface area configuration should not apply for local connections.
Try re-installing the latest MDAC on the server. I once had a similar problem and this solved it.
[http://www.microsoft.com/downloads/details.aspx?familyid=6c050fe3-c795-4b7d-b037-185d0506396c&displaylang=en][1]
Based on the error looks like the code is attempting to connect using named pipes, rather than TCPIP. You may actually need to specifically indicate in your connection string that the sql provider should connect using tcpip, so your connection string would look like the below.
Using Integrated Authentication (windows):
Integrated Security=SSPI; Data Source=SERVERNAME; Initial Catalog=DATABASENAME; Network Library=DBMSSOCN;
Using SQL Authentication:
UID=USERNAME; PWD=PASSWORD; Data Source=SERVERNAME; Initial Catalog=DATABASENAME; Network Library=DBMSSOCN;
I've seen something akin to this happen before, where for some reason "named pipes" is used by default as the transport/connection layer, especially since both the web application and sql server are running on the same machine. I generally always use tcpip as the transport, or network library.
Another troubleshooting technique is to use a UDL (or data link file) to troubleshoot the connection. This allows you to switch between connection providers (ODBC, OLEDB, etc) and to set other connection options.
On the desk top of the machine right click and choose new -> text document.
Rename the *.txt file to TestConnect.udl (name doesn't matter just needs to be .udl extension). You should see the icon change from a text file icon to an icon that shows a computer on top of a data grid, or something like that (in other words windows should have an icon for it.).
Now double click the file and you will see a "Data Link Properties" applet appear.
Click the Provider tab, and you will see a list of different connection providers. I'd start by just choosing "Microsoft OLE DB Provider for SQL Server". We can use this to confirm that OLE DB can connect or not.
Click next, and enter the servername or ip address. Select Windows NT Integrated security. (You can always come back and change it to use a sql login.) At this point you can click "Test Connection". If the connection succeeds, then select a database name from the drop down list.
Lastly, if the connection fails, select the "All" tab, and then look for "Network Library" and edit its value, setting it to "DBMSSOCN".
Go back to the connection tab and click "test connection" again.
Repeat steps 4 and 5 this time with the "SQL Native Client" selected.
Hope this helps.
At the prompt does:
osql -E -S
... get you a > prompt ?
Did you try specifying the instance name in the connection string? Apparently sql server express, in particular, is finicky about having the instance name.
I've also started to poke around with the SQL Server Configuration Manager. So did you click into "SQL Server 2005 Network Configuration" and then look at "Protocols for InstanceName"? And you enabled TCP/IP and Named Pipes?
Did you also look at the "SQL Native Client Configuration" --> "Client Protocols", and you see that TCP/IP and Named Pipes is enabled there as well?
Using the SQL Server 2005 Surface Area Configuration tool, click the "Surface Area Configuration for Services and Connections", then under "Database Engine" --> "Remote Connections" what is selected? Since it appears that you are attempting to connect using Named Pipes you will need to make sure that "Local and remote connections" and "using both tcp/ip and named pipes" is selected.
As you probably know, once any changes are made, you have to stop and restart the sql server instance via Management Studio (you don't need to reboot the entire machine, although rebooting the entire machine will get you there).
And my last piece of advice. Step away from this for a while, and get your mind off of it for a few minutes. When you dive back in, you may find something you missed or overlooked before.
I fixed the issue that I had with the connection. The problem was on my application. The cause of the issue was that a connection string to the development (instead of the production) database, was hardcoded by one of the dialogs that generates the datasets. This dialog placed the connection string both on the web.config, and on a hidden sourcecode file called "Settings.settings.cs". The problem was solved by fixing the connection string to the correct location.
The error message was totally misleading, but I was able to find that by following all the methods presented on the stack trace.
So if you ever find this error message, there are tons of possible causes. Your first bet is to follow the usual steps for this error, which are checking that the server allows remote and local connections, and restarting the browser service.
If that doesn't work, check the stack trace, look for code that is in your application, put a break point there and explore all the properties on the connection string. At least that's how I solved it.

Resources