I am using VSTS 2008 + C# + ADO.Net + SQL Server 2008. My questions about what kinds of communication protocols SQL Server 2008 will be using, more details of my questions,
If the connection string looks like this, whether Named Pipe or TCP/IP is used? Will different communication protocol being used dependent on whether client and SQL Server on the same machine?
Data Source=labtest1;Initial Catalog=CustomerDB;Trusted_Connection=true;Asynchronous
In SQL Server Configuration Manager, there are items called "SQL Server Network Configuration" and "SQL Native Client 10.0 Configuration". I find both of them has configuration options (for communication protocols) of Named Pipe or TCP/IP, what are the differences between "SQL Server Network Configuration" and "SQL Native Client 10.0 Configuration"?
According to SQL Server 2008 Books Online, this is what happens:
Connecting Locally on the Server
When you connect to the Database Engine from a local client (the client application and SQL Server are on the same computer), the connection uses shared memory protocol by default. SQL Server Native Client accepts any of the following formats to connect locally using the shared memory protocol:
""
"\" for a named instance "(local)"
"(local)\" for a named instance
"Localhost"
"localhost\" for a named instance
A single period "."
".\" for a named instance
To connect locally using another protocol (for troubleshooting), do one of the following with the protocol enabled:
Connect to a client alias that specifies a protocol. For more information, see "Aliases" in SQL Server Configuration Manager help.
Prefix the computer name with the protocol (for example, "np:" or "tcp:").
Connect to the IP address which results in a TCP/IP connection.
Connect to the fully qualified domain name (FQDN) which results in a TCP/IP connection (for example, "..com"
Connecting over the Network
By default, the default protocol for SQL Server clients is TCP/IP. If the connection cannot be made using TCP/IP, the other enabled protocols are attempted. A shared memory connection cannot be made over a network. Use SQL Server Configuration Manager to enable or disable client protocols, and to change the order in which connection attempts are made.
In the Sql Server Configuration Manager, you can define an order for the client protocols - I would assume that's the order the client tries to connect to SQL Server with. Whichever protocol is the first being supported by the server will be used.
AS for the configuration utility:
SQL Server Network Configuration is all about configuration of network protocols on the server side of things
SQL Native Client Configuration is the client-side configuration
If you have a dev box with both on it, you'll see both. A regular PC connecting to a SQL Server typically doesn't have SQL Server itself installed on it locally, so the server-side settings are meaningless there, obviously.
Marc
The settings configured in SQL Server Native Client Configuration are used on the computer running the client program. When configured on the computer running SQL Server, they affect only the client programs running on the server.
Microsoft SQL Server clients on a machine communicate with SQL Server servers using the protocols provided in the SQL Server Native Client library file.
Remember that these settings are not used by the Microsoft .NET SqlClient. The protocol order for .NET SqlClient is first TCP, and then named pipes, which cannot be changed.
Related
I'm having trouble connecting with my .NET 5 web app to an Azure SQL DB.
The weird thing is that I can connect to the DB using Azure Data Studio.
I've configured the Azure SQL Server firewall to accept connections from my IP address, and all of the Inbound/Outbound IP addresses of my Azure App Service.
Before adding my local IP address to the firewall, I could not connect with Azure Data Studio, so that works as intended, but then I use the connection string provided by Azure itself (in ADO.NET format, since I'm using Entity Framework) inside my web app, and the app can't connect to the DB (it times out with 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: TCP Provider, error: 40 - Could not open a connection to SQL Server)).
I can't really understand why my localhost instance can't connect, as the IP address trying to connect to the db is the same as when I use Azure Data Studio!
And also the App Service instance in Azure can't connect either (in the SQL Server's firewall I've also enabled connectivity from Azure App Services!!).
The connection string is of the form
Server=tcp:[my server].database.windows.net;Initial Catalog=[my db];Persist Security Info=False;User ID=[my username];Password=[my password];MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
Any hints?
EDIT:
to recap as requested,
dotnet run locally doesn't connect
containerized app service doesn't connect
Azure Data Studio locally does connect
I've found out the issue in the meantime, but I don't understand the cause:
dotnet run from WSL doesn't work; if I run the app from Windows it does work!!
I've therefore changed the App Service to build from source instead of running a containerized image, and it also does work.
Why would running the app locally from WSL instead of Windows result in the Azure SQL Server's firewall blocking me?! Is WSL exposed to the internet with a different IP address?
And why does the same happen to an Azure App Service that runs the containerized version of my app?
Since you can access the server from the same machine, it is not a firewall issue.
There are two possibilities you could check:
The connection string that your program is using is not what you expect. Try logging the connection string.
The server is configured to use named pipes and not tcp. Azure Data Studio is configured to use named pipes and therefore works. Try checking the server configuration.
My WPF application cannot connect to an external SQL Server. The host machine has port 1433 open, has a static IP address, and port forwarding from the IP address to host server has been enabled.
Most puzzling, I am able to connect from SQL Server Management Studio on the client machine using the same connection name, and same server authentication details, but I cannot connect with my .NET application. I am using Entity Framework, which is working until the app is built and queries the server.
Therefore, I have ruled out server hosting issues, and connection string issues, as I'm able to connect while working on Visual Studio, but cannot connect while app is running.
The error (inner exception) is
TCP provider, error 0 - Access is Denied
if you are able to connect through SSMS remotely to sql server there should not be problem for connecting through application using ado.net, you need to recheck your ef configuration and connection string
I assume you are using entity framework 6.
Based on the approach like code first based or designer model based you need to validate your configuration
Please refer to below link
https://learn.microsoft.com/en-us/ef/ef6/fundamentals/configuring/connection-strings
If you are using ef core refer to below link and validate your configuration for connection string
https://learn.microsoft.com/en-us/ef/core/miscellaneous/connection-strings
I have a SQL Server running on Microsoft Azure. I want to connect it to My Project in Visual Studio 2015 Community. I have added my IP address in firewall on server. I have also made my port 1433 open for sql. But when I try to connect to database this error shows up. Error Message in SQL Server
It appears that this is a two step process and you either missed the VM configuration or the Azure configuration. Based on what you said I believe it is the Azure configuration that may have been missed. This blog post appears to highlight the necessary things that need to be done to connect.
https://blogs.msdn.microsoft.com/ggaurav/2014/01/08/connect-to-sql-database-on-azure-iaas-from-ssms/
Below is an excerpt:
The two settings which you have to make sure you are checking are :
Endpoint is configured for the port on which SQL server is listening ( generally 1433) on the VM machine.
Ports are opened on the VM machine. Even though as per the documentation Cloud adaptor takes care of opening the firewall ports,
it doesn’t work for the normal connections which you are trying to
make. Just type in ” wf.msc” and create a rule for both outgoing and
incoming for TCP port 1433.
As soon as you are done with these two, you would be able to connect
to the SQL server on the VM machine.
According to your description, I guess your SQL database is a Azure service, not install SQL on Azure VM.
If I understand it correctly, we should check SQL database firewall settings and confirm the name of your database.
The error code means, this error could occur because either the
firewall on the server has refused the connection or the server is not
configured to accept remote connections.
We can via Azure Portal to check the firewall settings:
Make sure the Allow access to Azure Services is ON,
And make sure your client IP address have added to the Client IP address list.
Also we should confirm the name of your database, make sure we are connect to the right SQL database.
I have also made my port 1433 open for sql. But when I try to connect to database this error shows up.
You also need to enable 1433 port in Network Security Group which related to your VM. Steps below are for your reference.
Find the Network Security Group name which related to your VM in Netowrk interfaces panel.
Open this NSG, click [Add] button in the Inbound security rules panel
Add a rule as following.
After that, we could access the database hosted in VM using following server name format.
Server name format.
[IP address/dns name],1433
For example,
13.81.50.123,1433
So Im running a Sql Server 2012 in a virtual machine on my computer and I want to be able to connect on it with the SqlConnection on Visual Studio, but I have no idea what to put on the servername parameter.
I dont know if I have to put the vm ipaddress or the machine address "WIN-NIJ53etc\SQLEXPRESS"
UPDATED:
FOR MIGRATING BETWEEN SQL CE AND SQL SERVER: Please take a look at this instruction here.
You should follow these steps:
1- Set the virtual machine to have a physical IP address.
For configuring network on Microsoft Virtual PC: http://support.microsoft.com/kb/833134
2- Be sure that you can see the VM with a static IP address. (ping is a good idea for checking that, but don't forget to turn off the firewall on the target machine, I mean the machine you wanna ping. There is no need for the server to see the client, so check that your client (in this case your VM) can ping the server IP address like "ping 192.168.10.1 -t")
3- Use Configuration Manager (All Programs\Microsoft SQL Server\Configuration Tools) and set SQL port and visibility over network.
Reference: http://msdn.microsoft.com/en-us/library/ms189083(v=sql.105).aspx
4- Restart the SQL server.
5- Be sure that "SQL Server Browser" service is started. (incase you wanna use the instance name to access the SQL server)
6- Config the firewall on the host machine (machine that has SQL engine) and add the port you specified in the Configuration Manager to TCP Inbound rules.
Take a look at here: http://www.tavislovell.com/post/How-to-configure-Windows-Firewall-to-allow-access-to-SQL-Server.aspx
BUT be advised that you should set the port specified in the Configuration Manager (default is 1433 but sometimes it's dynamic and you should set it again)
7- After you set the port and network visibility, you should change the "Server" value in the connection string to this format "IPAddress, PORT" like "192.168.10.50, 1433" (When you specify the port, there is no need to set the instance name like this "192.168.10.50\SQLEXPRESS")
Hope it helps
Ahh the joys of SQL Server Installation setup.
Make sure you have:
Network communication between the VM and the client computer (ping will work)
The SQL Server Service configured to start automatically or that it is started
The service configured to use TCP (if you don't want to use Named Pipes)
Either the SQL Server Browser enabled and started or that a static port is configured (1433 or similar)
The firewall rules configured to allow 1433 (or the port you have chosen) and 1434 (if you are using browser)
The connection string using the proper format Computer Name\Instance (to use browser) or Computer Name,port (if you are using a static port
There is a good tutorial on MSDN that may prove helpful. With specific regard to the Server Name/IP question, it doesn't matter so long as the client computer can resolve it. If you are testing, "IP,Port" is the most reliable (E.g. 10.10.10.100,1433) as it does not depend on NetBIOS, DNS nor the SQL Browser service.
Developed a Windows application that remotely accesses an SQL Server online. However, the client's ISP blocks port 1433. What are the other options to connect to SQL Server from the windows app?
SQL Server should have a network utility where you can configure the port to be used. Contact your client's ISP to see which ports are open (they may even be able to open up 1433 for you) then configure the server to use that port.
In my install, you select: "Start > All programs > Microsoft SQL Server > Server Network utility", select "Enabled Protocols" then "TCP/IP" and "Properties".
From there you can set the default port to a more accessible one.
You could change the port number that SQL Server runs under, to use a port that is actually open at the ISP.
Since 1433 is the default port for SQL Server, it is a common target for hackers. Some ISPs pick an arbitrary port number to obfuscate this. You may need to find what port number that is from them.
Another option is to use a WCF Web Service hosted in IIS and have your windows app call this service.