.NET SQL Server Connection by name and IP differs in behavior - sql

Not sure if this is a StackOverflow question, but we hit this really strange problem with our ASP.NET 4 web app.
So, there is a typical connection string to SQL Server with Data Source specified in web.config.
SQL Server is run on VM on the same host as Web VM runs. They are in one network. If we specify connection using VM name, like "sql-server-vm", the web app works properly without any issues. But if we specify IP address of SQL Server VM instead, we start running into transient issues, like long server answers or timeouts.
Trying tracert the IP from the Web server VM shows the proper IP, so it's definitely the same machine and it is avaliable by name and IP. We are using ASP.NET Web API 2, ADO.NET, SQL Server 2014 SP3 in this project.
Is it possible that connection using ADO.NET does not properly work with IP address, but works with SQL Server Instance name? I cannot imagine a reason for this, but this is clearly what happens.

Related

Can't reach my SQL Server hosted in a Windows Server VM, any ideas?

Well, I'm having the following situation.
I'm trying to set up a testing environment which consist of having a SQL Server on a Windows Server VM hosted on Google Cloud Platform (GCP). So far I've installed SQL Server on the VM and configured an instance with SQL authentication. Then I installed SMSS to access using the instance name and my credentials. At this point everything works well.
The problem comes when I try to access my SQL Server via SMSS from another computer. As the instance I'm using my GCP VM IP Adress and the credentials I've created before. The error is as follows:
So far I've done the following configurations:
Enable TCP/IP via SQL Server configuration manager.
I made sure that port 1433 was properly configured in the TCP/IP properties.
Created a new inbound rule on the Firewall to allow TCP connections using port 1433.
On the SMSS, checked that allow remote connections is enabled.
Restarted SQL Services from SQL Server configuration manager and services.msc
With above configurations it should work! But I've no idea what's happening.
Anyone who could give me a hint of how this could be solved, I'd appreciate it.

SQL Server Browser - Startup Type - Best Practice

During the installation of SQL Server Express 2012 on a new machine, I am able to specify the startup type of both the SQL Server Database Engine and the SQL Server Browser.
By default, the SQL Server Database Engine has a Startup Type specified as Automatic.
SQL Server Browser has a default Startup Type of Disabled.
After reading about what function SQL Server Browser serves, it would seem that it is something you would want to have running all the time, since it essentially keeps tabs on the various DB instances, and seems like it would speed up development for example.
What are the pros and cons to setting the Startup Type of the SQL Server Browser to Automatic for example? Or to get any use, would you need to set it to Manual and then specify it launch at startup?
Thanks.
From my experience (after making direct access to SQL Server) SQL Server Browser useful if you have Named instances and\or nonstandard(standard is 1433)\dynamic TCP ports.
SQL Server Browser actually listens on UDP port 1434 (default, should be open in firewall) and returns Server\Instance name to IP address\port. If you want to connect from remote client to some MyServer\MSSQL2008 or get available in your network SQL Server Browser will return list of "Instance name\IP address\Port" to your client.

Unable to connect to SQL Server 2005 installed on Win7 virtual machine

I am not able to connect to a SQL Server 2005 hosted on a Win7 virtual machine. I am new to VM, can someone help me locate the problem?
I am able to connect another SQL server which is installed on the local machine.
When you say you can't connect - that can mean a lot of things - really you need to be much more specific.
In addition to the comments and answers already here - If you're having trouble connecting to it in Sql Server Management Studio - you should open Configuration Manager on the VM itself and make sure that Shared Memory and Named Pipes are enabled (open the SQL Server Network Configuration node in the tree).
For example, SQL Server Express instances are configured by default to reject the kind of remote connection that SSMS wants to open by default.
first of all check your connection string (for reference):
http://www.connectionstrings.com/
Second you need to add an exception in the guest machine firewall or completely disable it (port 1433 is for sql tcp/ip access).
this works fine for me:
SQLConn.ConnectionString = "Network Library=DBMSSOCN; Data Source=xxx.xxx.xxx.xxx,1433;
Initial Catalog=mySQLServerDBName; User ID=myUsername;Password=myPassword"
good luck

SQL SERVER 2005 Connectivity Problems

I am having a hell of a time trying to connect to the SQL SERVER 2005 database. I am using Windows 7.
Here is the screenshot of the error thrown:
(source: highoncoding.com)
I have been battling this issue for the past week and still no progress.
I have tried the following in the server name:
(local)
localhost
computername
none of them worked!
I just checked in the services section and SQLSERVER EXPRESS is not even there. I am using the following post as a reference:
https://serverfault.com/questions/11745/i-cannot-connect-to-my-local-sql-server-2008
This instance of SQL Server is running on the same PC you're connecting from? That's the implication of 'local'.
Possibilities :
1) Try (local) instead of local for the server name
2) Try 'MSSQLSERVER' as the name
3) Check the SQL Server Configuration Manager shows the same configuration options you're attempting to connect with, eg the same instance name, Named Pipes enabled, services running ok, etc.
EDIT :
Ok, what are you using to connect with? SQL Server Management Studio Express? Are you sure you installed an instance? The lack of SQLExpress in the services list would seem to indicate otherwise.
When you connect to a SQL Server you specify the name in the form {computername}\{instancename}. The {instancename} is the name of the SQL instance which was chosen during the SQL Server installation. For {computername} you can substitute the special names . or local when connecting to the localhost machine. If the SQL Server was installed as the Default instance then the instance name part must be omitted, so the connection Server name becomes just the computer name.
SQL Server Express installs by default an instance named SQLEXPRESS. The corresponding NT service name is MSSQL$SQLEXPRESS. The Server name in the connection dialog is .\SQLEXPRESS, local\SQLEXPRESS, localhost\SQLEXPRESS or {computername}\SQLEXPRESS (they're all the same).
If the SQL Server was installed as the Default instance name then the corresponding NT service name is MSSQLSERVER. The Server name in the connection dialog is ., local, localhost or {computername} (they're all the same).
If the SQL Server was installed as a named instance then the corresponding NT service name is MSSQL${INSTANCENAME}. The Server name in the connection dialog is .\{INSTANCENAME}, local\{INSTANCENAME}, localhost\{INSTANCENAME} or {computername}\{INSTANCENAME} (they're all the same).
When connecting from a remote computer to a SQL Server instance the SQL has to be configured to allow remote connection How to configure SQL Server 2005 to allow remote connections.
Check your SQL server configuration, make sure the TCP connections are enabled. You can also check that the SQL Browser service is started. Make sure you do not have a firewall that gets on the way. Make sure the SQL Server service is also started.
Did you install SQL Server on the default instance, or have you used named instances? If you've used named instances then the server will be server\instancename. If you don't know, then have a look in the Services administrative tool; you'll be able to determine the instance name, if any, from there).
You could also try connecting with the server name as a single period (i.e. simply ".") [caveat... I've not got access to SQL Server at the moment, but I think I've used this before now].

When trying to access a SQL Server 2008 server in my domain, I get a "server not found or was not accessible" error

When setting up a system that requires a remote computer to access SQL 2008 stored on another computer in the same domain, I'm running into the following error:
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.
When I installed SQL Server, I was sure I set up the system just so. How can I troubleshoot this?
I appreciate this thread is old now and already has an accepted answer, but I found a slightly different solution with regards to this issue that others may find useful. From reading this issue description I found that there were two SQL Server services in the standard Windows Local Services control panel: MSSQLSERVER and SQLEXPRESS (see below).
I found that SQLEXPRESS was running, but MSSQLSERVER was not. So I simply started that service, and I was able to connect to SQL Server again.
A couple of things to try...
check the Configuration settings to ensure that the TCP protocol is enabled.
try accessing the remote server via IP instead of the server name, this has worked for me in the past (oddly).
I'm assuming its running on the default port, if it isnt then you will need to specify the port number after the server-name / ip separated by a comma:
sql-server-name,{port}
Look at the name of the SQL server instance and make sure it is what you are using to connect to it. Also, look at the SQL Server Network Configuration under Configuration Tools. I worte an article about a very similar problem (if not the same) here:
Having had this a few times even with named pipes the first thing I always try is pre-pending the server name before the named instance; so SERVER\namedinstance. You can manually overwrite the dropdown values in the connect . So ideally in the setup it should have a brief tip below the named instance box like Enter SERVER\namedinstance. Although knowing MS if you entered this you'd probably end up with SERVER\SERVER\namedinstance...!
You can also use the browse option (bottom of server dropdown) and if you're lucky it may be in the 2nd tab (Network Servers) - even if it's a local install.
The program you are running needs to be running under an account which has access to the network (and depending on protocol chosen, may need access to the SQL Server by role or whatever). This error indicates that it is not finding the server on the network by name or IP.
The most common case I have seen this is when you have a web app running under a local account which does not have network access attempting to access SQL Server on another machine.
If you have access to the server that SQL Server is running on, you can try:
-Opening SQL Server Configuration Manager
-In the left pane, click 'SQL Server Network Configuration' and then 'Protocols for [instance name, possibly SQLEXPRESS]'
-Right click TCP/IP again and you'll see the port used. Mine was listed under IPAll/TCP Dynamic Port.
-In SQL Server Management studio add the port name to your connection string as follows:
if you were connecting to:
MYSERVER\SQLEXPRESS
the port is specified as
MYSERVER,2071\SQLEXPRESS