Invalid connection string when connecting to SQL Server Express - sql-server

I tried every single variation that I could find on the internet. Everything. And still every time I get the very same exception:
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: TCP Provider, error: 25 - Connection string is not valid)'
With this weird inner exception:
SocketException: The operation completed successfully
When I specify the port directly, then I end up with this wonderful exception:
An attempt was made to access a socket in a way forbidden by its access permissions
No matter what, it doesn't work. Moreover I'd like to have MS SQL Management Studio open while testing (that was the only process which could block the port).
So why does it not work? Management Studio can connect with IP\InstanceName without a problem. Why is the System.Data.Sql.SqlConnection class incapable of doing so?
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.DataSource = "tcp:***.***.***.***\\SQLEXPRESS";
builder.InitialCatalog = "MyDB";
builder.Password = "MyPass";
builder.UserID = "ID";
builder.IntegratedSecurity = false;
_connection = new SqlConnection(builder.ToString());
FYI: I am using the ConnectionStringBuilder, so there shouldn't be any issue. Server name, instance name, SQL user and password are valid and I did explicitly set Integrated Security = False.

The problem was (which was not really clear) that UWP requires a capabilitiy in order to run that code. I read somewhere that you would need Enterprise Authentication which was not the one. Since my program and server are in a closed, private network I enabled Private Networks (Client & Server).
The one you would need is Internet (Client & Server). Sadly the exceptions don't hint to that and the fact that SqlClient on UWP requires this to work is nearly nowhere mentioned or not stressed enough so you wouldn't overlook it.
Solution found in this .Net Standard issue.

First of all try to connect to this database using SQL Server Management Studio.
If you get the same error, it means that there is a problem with the server not (or not only) with your connection string.
Here is some of possibilities :
1- Remove 'tcp:' from this part: builder.DataSource = "tcp:...\SQLEXPRESS";
2- On the server the SQL Server services (SQL Server or SQL Server browser) are stopped.
To activate go Services and start stopped services.
3- May be the server doesn't accept remote connections:
In this case on the server open SQL Server Configuration Manager
And activate tcp ip.
You should restart SQL Server service after this operation.
Tell me if it works for you.

Related

HTTP Error 500.30 - ANCM In-Process Start Failure - An error occured during migration

I have read this thread, however unfortunately couldn't find the solution to my problem. I have an ASP.Net Core project (that's called Rent) and it works without any problem on my local machine. However, once I publish the project to the IIS (still in development mode) I get the below error
fail: Rent.Program[0]An error occured during migration
Microsoft.Data.SqlClient.SqlException (0x80131904): 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. Cannot create an automatic instance. See the Windows Application event log for error details.
---> System.ComponentModel.Win32Exception (0x89C50118): Unknown error (0x89c50118)
The connection string is called DefaultConnection and is the environment variable. Can anyone help me please? Can provide any additional information if required.
The first thing you should check is that your SQL Server instance is up and running and that your database is still available. This error means quite literally that it can't establish a connection to SQL Server from the Secret Server application.
And you can also check follow things in your environment:
Is something blocking the connection between your Secret Server server and SQL Server?
The standard SQL port is 1433. Check with your server administrator - is the Windows Firewall in use, blocking this port on your SQL server? Check with your network administrator - is there a firewall at some point in between that has closed off this port? Keep in mind that if you use a custom port for SQL, it need to be specified the Secret Server database connection using a SQLSERVER,port type of format.
On the server hosting your SQL Server database, is the SQL Server
service running?
Open services.msc or SQL Configuration Manager to view the status of your SQL Server service.

Unable to connect to another connection in SSAS Tabular

I have a very weird issue with SSAS Tabular connecting to a SQL Server source database. I've spent almost the entire day on this, and searched online in various ways to find a helpful answer, but none of the suggestions solved this mysterious problem for me.
It used to work fine, but I tried various connection settings (Windows vs SQL authentication, and different impersonation modes), but now I no longer can get it to work (even if I revert back to the previous bim file in source control).
When I process a table from the WORKSPACE database (through SSMS), it works. But when I process a table from the DEPLOYED database (still through SSMS), it does NOT work.
The connection I am using is:
-SQL Server Native Client 11.0
-Windows Authentication
-Impersonation mode of a Windows account (which has the appropriate permissions)
The source database is in a SQL Server database located on a different server (but in the same network).
I have searched everywhere online, but didn't find anything that could help me.
I have tried changing the connection driver (OLE DB Provider for SQL Server), and I have restarted the SSAS Tabular service.
The full error message I get when trying to process a table on the deployed database is:
Failed to save modifications to the server. Error returned: 'OLE DB or ODBC error: Login timeout expired; HYT00; 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.; 08001; Named Pipes Provider: Could not open a connection to SQL Server [5]. ; 08001.
A connection could not be made to the data source with the Name of 'DataWarehouse'.
'.
In fact, after I tried a second time to restart the SSAS Tabular service, the error message I get after attempting to process a table is slightly different:
Failed to save modifications to the server. Error returned: 'OLE DB or ODBC error: 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.; 08001; SSL Provider: The requested security package does not exist
; 08001; Client unable to establish connection; 08001; Encryption not supported on the client.; 08001.
A connection could not be made to the data source with the Name of 'DataWarehouse'.
'.
According to your description, it seems to be related to connection problem. You need to check whether corresponding SQL server service and SSAS Service is running(check server which contains "DataWarehouse" is running and can be connected). You could go to "SQL Server Configuration Manager " to restart them.
In addition, you also need to make sure your current windows credential can access this database(if you use window credential). And check whether this server enable remote connect.
Zoe

Unable to connect on AWS - RDS DB : SQL Server 2012 Express

I'm new in AWS world. I have an issue to access to my instance of Microsoft SQL Server 2012 Express (11.00.5058) on RDS (US-East-1a).
When I have created DB instance, I was able to access to it, create some tables, transfer data, etc.. everything worked fine !
I didn't change anything and few hours after some inactivity, I try to access to the SQL Server instance by using Microsoft SQL Server Enterprise Manager but I was not able to connect to it anymore. I got following message:
Cannot connect to m3instance.cqbvdcpcgye3.us-east-1.rds.amazonaws.com,1433.
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 wait operation timed out.) (Microsoft SQL Server, Error: 258)
Currently, instance appears as available, the security group is 'rds-launch-wizard (sg-be4afcc6)'.
I have try to connect to 1433 port on via Telnet and no success.
Instance name is m3instance.cqbvdcpcgye3.us-east-1.rds.amazonaws.com.
Do you have any idea what append ?
Thank a lot for your help.
UPDATED
Telnet command return this :
telnet m3instance.cqbvdcpcgye3.us-east-1.rds.amazonaws.com 1433
Connecting To m3instance.cqbvdcpcgye3.us-east-1.rds.amazonaws.com...
Could not open connection to the host, on port 1433: Connect failed
DB settings :
Security Group :
VPC :
I have tried to connect by using my home connection, or coffee shop wifi without success. I didn't check what was my IP address at this moment but the strange thing is that I was able to connect to SQL server when I have created DB instance (create SQL table, transfer data, etc...) but after few hours (and without any change), I was not able to access to it.
May be if I add a new rule in security group / inbound rule like this,it will fix my issue : (i didn't try yet because I'm at work right now and we have firewall that block SQL access)
At this point, data are not sensitive and security is not a big issue.
Thank again for your help guys !!!
This because maybe you choose the default group , so Edit Your Security Group And In (INBOUND) ADD RULE and allow connection from (ANYWHERE)
Actions
Edit inbounds rules
MS SQL TCP 1433 My Ip (Automatically appears the public ip of your router)
Save
Try connect

Cannot connect to SQL Server, error: 0 - No Connection could be made because the target machine actively refused it

I'm new to SQL related matters so please bare with my lack of knowledge and asking a question which has been asked countless times before.
I have to connect to a SQL database server which is located at a remote location at xxx.xx.xxx.xx:3306, but every time I try to connect I get the same 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: TCP Provider, error: 0 - No connection could be made because the target machine actively refused it.)"
I get this same error whether I try to connect using SQL Server Management Studio or in a C# program via:
SqlConnection myConnection = new SqlConnection(...)
myConnection.Open();
I've tried it on two different computers, both on the same home network. I've had a look at the SQL server configuration manager on the computer which I installed SQL Server on, enabling TCP/IP and fiddling with the port values settings, but I'm guessing this is just for configuring an SQL server on my computer and irrelevant to connecting to a remote one. I shouldn't even need to install SQL server to do queries on a remote server anyway, right?
I've turned off my Windows firewall and my router firewall, though ShieldsUP still says
Port: 3306
Status: Stealth
Your system has achieved a perfect "TruStealth" rating. Not a single packet — solicited or otherwise — was received from your system as a result of our security probing tests. Your system ignored and refused to reply to repeated Pings (ICMP Echo Requests). From the standpoint of the passing probes of any hacker, this machine does not exist on the Internet. Some questionable personal security systems expose their users by attempting to "counter-probe the prober", thus revealing themselves. But your system wisely remained silent in every way. Very nice.
I read that this is irrelevant as well, since I'm not the one hosting the server, but when I was given the address, I was given the port as well, so I must have to do something with it. I'm just not sure what. My understanding of ports really is quite shaky.
I've been trying this for over a day now, and I can't think of anything more I can do.
EDIT: I fixed the problem. I had to use MySQL, not MSSQL. Doh. Sorry guys.
If you are sure the remote SQL Server is running on port 3306 (otherwise I'm not sure why you talked in the question about that port specifically), try the following connection string:
user id=username; password=password;
data source=123.45.678.90,3306;
initial catalog=dbname;
Network Library=dbmssocn;
I think without the port you'll have trouble if the other end has disabled the SQL Browser service. You should also make sure it isn't a named instance, in which case you may need:
user id=username; password=password;
data source=123.45.678.90\InstaneName,3306;
initial catalog=dbname;
Network Library=dbmssocn;
First of all the database is local or distant ?
The you have to ensure that your connection string is well written.
Here's an example of a valid connection string :
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
More about connection strings :
Connection Strings
Now if everything is set up correctly you have to enable remote connections to SQL Server on the host. To do so please refer to this article :
Enable SQL Server Remote Connections
Just go to ypur serveices and check whether your SQL Server (MSSQLSERVER) is running.Most of the time this error happens when SQL Server (MSSQLSERVER) is stopped.
Then select it right click and click start.problem solved !!!

Connecting to remote SQL Server 2008 from Windows Azure

I am trying to connect to a SQL Server 2008 instance from a Windows Azure worker role (it's not SQL Azure, but a remotely hosted SQL Server 2008 Standard Edition), but I get the following error message
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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at ...
The code snippet is the following:
using (var connection = new SqlConnection("MY CONNECTION STRING")
{
connection.Open();
var command = new SqlCommand("Select 1", connection);
try
{
var res = command.ExecuteScalar();
}
catch (Exception e) {
Log.Log("error", e.ToString());
}
}
When I run the snippet from my local command-line (directly accessing the remote SQL Server), it works OK, yet when run from Windows Azure, I end-up with the error message outline here above. In order to make sure there were no problem with the connection string sure, I re-try by hardcoding the string in the source code pushed toward Azure (just to be 100%, but I am still hitting the very same problem).
I have no firewall setup on the SQL Server 2008 instance, and I running out of ideas.
Can someone spot what I am doing wrong here?
I've noticed some issues with the SQL Server Resolution Protocol (or the SQL Server Browser) from Azure worker roles when connecting to external non-Azure SQL Server instances running on ports other than 1433. In these cases it can help to explicitly specify the TCP port of the instance in the connection string:
Data Source={domain/ip},{port};
Network Library=DBMSSOCN;
Initial Catalog={dbname};
User ID={user};
Password={pw}
See also Connect from Azure to an SQL Server Named Instance
Can you control your Azure instance through Remote Desktop?
If you can, log on, and try:
telnet yoursqlserverhostname 1433
If this blocks, you know that the network is not configured correctly. Usually a firewall issue, on either host or the network in between.

Resources