sql connection over VPN in WPF program - c#

I'm trying to connect to a remote server via VPN, and I have connected to the VPN successfully, and when I'm using management studio, it's also all good and well, but when I'm trying to connect via my WPF program I'm getting this error
On connection.Open();
{"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: 0 - The remote computer refused the network connection.)"}
and this is my Connection string as copied from visual studio
Data Source=192.168.232.10\PRI2014,4443;Integrated Security=True;User ID=c_Vision;Password=********;Connect Timeout=15; Encrypt=False; TrustServerCertificate=True; Trusted_Connection=True;
i have looked here and here for answers

Port number should be placed after Ip
Data Source=192.168.232.10,4443\PRI2014;Integrated Security=True;User ID=c_Vision;Password=********;Connect Timeout=15; Encrypt=False; TrustServerCertificate=True; Trusted_Connection=True;

Related

I am unable to connect to my SQL Server 2008 on Remote Server

I am Trying to connect to my SQL Server but I keep getting this 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) (.Net SqlClient Data Provider)
This is my connection string
<connectionStrings>
<add name="myDB"
providerName="System.Data.SqlClient"
connectionString="Server=Usman-PC\SQLExpress; Database=myDB; Integrated Security=True;"/>
</connectionStrings>
I have google for solution and tried many things but keep getting this error.
I was developing accounts app and now it is time for deployment on production server. Please somebody help me.
Below are my settings
Computer name: Usman-PC
WorkGroup: USMAN-SERVER
Ip address: 192.168.0.1
Server Name: Usman-PC\SQLExpress
Instance Name: SQLEXPRESS
What I have tried:
I have looked at connection setting in Server Properties and they are good.
I also have checked and server is running.
I also have enabled TCP/IP and set the port to 1433.
I also have added new rule for port 1433 in firewall.
I am also able to transfer files between both computers.

How to solve this error message if my network is working well

i am trying to reach a network based server program(on visual studio 2013& sql server 2012). On another machine of course. I searched that error and it says my db or server is not open to remote reaches. But i am %100 sure they are reachable.(My program's recent version is also used in my computer and it reaches db and the server.) I am sure my addresses and networks are correct and working. And also checked the ports etc. These were all i could reach. Do you have any other solution or guesses those i can try?
Thanks for your help.
"ErrorMessage: Server DB ye ulaşamadı(Says server DB is not
reachable.) Info: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) Yayin OrjErrorMessage: 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)"

Cannot connect to any remote database using SqlConnection

I cannot connect to a particular SQL Server 2008 database server from C#.
I am able to connect using SSMS, and run queries using SQLCMD, but when I try to connect from C# using the SqlConnection it fails to open the connection with a 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Here is my code:
using (SqlConnection conn = new SqlConnection(#"Server=LDNPSM050000137\PLN000000014T;Initial Catalog=MiscData;Integrated Security=True;"))
{
//exception occurs on this line
conn.Open();
//use connection
conn.Close();
}
I get a similar response using ODBC:
string connectionString = #"Driver={SQL Server Native Client 10.0};Server=LDNPSM050000137\PLN000000014T;Database=MiscData;Trusted_Connection=yes;";
using (OdbcConnection connection = new OdbcConnection(connectionString))
{
connection.Open();
}
This fails with an OdbcExcpetion:
ERROR [08001] [Microsoft][SQL Server Native Client 10.0]SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF].
ERROR [HYT00] [Microsoft][SQL Server Native Client 10.0]Login timeout expired
ERROR [08001] [Microsoft][SQL Server Native Client 10.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.
I have checked the server and instance name are correct, and the server is configured to allow remote connections because I can connect through SSMS. Does anybody have a suggestion of what the problem could be or how to resolve this?
Update:
In case this helps somebody diagnose the problem - This is specific to my machine/user account. My colleague can run the code fine from his machine. I am also able to connect to my local instance using a connectionstring with the appropriate changes to the Server and Initial Catalog.
The error occurs for all remote database servers.
I'm not sure if this is specific to my company's specific IT infrastructure - but the reason this was not working for me was because the project was saved in My Documents which stored on a network share. Apparently .NET will not let you connect to a remote database server when the executing code is located on a network share - it work fine when I copied the project to my local drive. I am using Windows 7 and Visual Studio 2012.
Network shares by default have partial trust, so things that work when a project is on your local drive, e.g. connecting to remote server, won't from network location.
You can give the network location full trust (https://msdn.microsoft.com/en-us/library/zdc263t0(VS.80).aspx) or move your project onto your local drive.
I think the problem is the Server value in your Connect string:
From MSDN
I think you need to do this:
Server=tcp:LDNPSM050000137\PLN000000014T
Server=np:LDNPSM050000137\PLN000000014T
Depending upon whether you want to use TCP or Named Pipes...

Remote access using C# application to database created using SQL Server 2014 Management Studio

I have a database called Library created in SQL Server 2014 under my locally created server instance. I am using that database as the datasource in my windows form application. It is working perfectly when on my computer, but when I run it on other machines, it stops with the error
Unhandled exception occurred...
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 connection to SQL Server)
I have started all services from configuration manager and have enabled tcp/ip under protocols for MSSQLSERVER. Is there any way I can accomplish this, or do I have to shift to local db?
Make sure that your connection string includes your remote machine name as part of the "Data Source", so something like :
connectionString="Data Source=machinename\SQLExpress;Initial Catalog=mydbname;Integrated Security=True"
note that this connection string will target a db name "mydbname", under the machine machinename which has a SQL Express instance.
if that didn't work let me see your connection string.

Connecting to a SQL Database

I am using Visual Studio and trying to connect to the Northwind database. I use the following connection command...
Data Source=C:\\Program Files (x86)\\Microsoft SQL Server Compact Edition\\v3.5\\Samples\\Northwind.sdf;Initial Catalog=Northwind;Integrated Security=SSPI"
I have also tried
Data Source=(local);Initial Catalog=Northwind;Integrated Security=SSPI
both cases I get an 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)
I can connect to an online database but not on a remote one. I have checked the config manager and all services are running.
Any helps please
there are lots of collections of connection strings so you can get help from here...
http://www.connectionstrings.com/sql-server-2008
The Visual Studio has tools to connect to databases. Using Server Explorer, you can choose which SQL Server you want to connect to and then choose the database from a list. Once you have successfully connected to one, its properties mention the connection string to use. No need to guess.

Categories