Cannot connect to local instance of SQL Server database using Entity Framework Code First - error: 26 - Error Locating Server/Instance Specified - sql-server

I have an MVC web application using EF 5.0 (Code first) that connects to a local database (on the same server) using this connection string:
"Data Source={server}\{instance};Database={database};user id=sa;password={password}"
The database is dropped and re-created when the DbContext is first initialised. After that it throws the following exception:
System.Data.ProviderIncompatibleException: An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct. ---> System.Data.ProviderIncompatibleException: The provider did not return a ProviderManifestToken string. ---> 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)
I've hosted another application on the same server, using exactly the same connection string to access the database using a SqlConnection object in old-school ADO.Net fashion which connects fine.
I've checked for similar posts and all suggest a number of things which I have tried but have not solved the problem:
Add TCP/IP aliases for server instances
Check firewall allows inbound connectivity via TCP:1433 and UDP:1434 ports
Check that SQL Server Browser is running on the server
Check that the connection string is valid and that the specified user has access to the SQL Server instance
Just to add a odd twist to the whole thing: I can connect to the same database on the same server from my workstation running IIS Express but as soon as it's hosted on the server I get the above problem.

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

Accessing a SQL Server from a Windows service running on a domain user

If I run the Windows service using the Local System account, I have no problems at all.
The service was developed using C#.NET. The connection string is like this:
"Data Source={0};MultipleActiveResultSets=True;Async=true;Initial Catalog={1};User ID={2};Password={3}"
If I run the service using a domain user, I get the error below when trying the connection to the SQL Server. (The service generates an error log where I can see what´s happening). I´m aware of the typical causes for this error, like enabling remote connection, protocol configuration and firewall. But the error occurs even running the SQL Server in the the same machine the service is running and only if I don´t run the service with the Local System account.
.Net SqlClient Data Provider - 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)
Even if I set the account as a local administrator I get the error.
What could cause this behavior?

MVC4 app not connecting to SQL Server when run on local machine

I have an MVC4 app that was working before I started working on it today. As far as I know I did not make any changes to the connection strings.
I have a connection string set to use a SQL Server 2012 database.
When trying to run the app from my local machine I get 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)
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
SQLExpress database file auto-creation error:
The connection string specifies a local SQL Server Express instance using a database location within the application's App_Data directory. The provider attempted to automatically create the application services database because the provider determined that the database does not exist. The following configuration requirements are necessary to successfully check for existence of the application services database and automatically create the application services database:
Sql Server Express must be installed on the machine.
If I run the app from the server that it resides on I do not get this error. I can also access the SQL Server database from both my local machine and the server with SQL Server Management Studio and Visual Studios built in Server Explorer.

SQLBulkCopy can't connect to SQL

When doing a SqlBulkCopy command in C#, I get an error that it can't connect to SQL Server (see error below).
The following is important to take note:
The same form have a GridView that displays information from the same table, so that means the Connection string is correct and SQL Server is accessible.
I can do the same operation from my machine using the same settings without problems, it's only on the client's machine where it have problems. Therefore SQL permissions are fine and do accept data.
The client is running the app (Framework 4.0) on Windows Server 2003 (it also fails on Win XP).
Doing a normal Insert statement works fine. Just not SqlBulkCopy.
What else can it be?
The error is:
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)

Resources