SQL Server Connection String - Different Domain - sql-server

I have a SQL Server connection string in a config file:
<add name="DbMaster" connectionString="Data Source=ServerName\NamedInstance;Initial Catalog=SomeDb;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>
This is fine if I am running from the domain where the SQL Server is located, but I receive the following error on a different domain:
System.Data.SqlClient.SqlException: An
error has occurred while establishing
a connection to the server. When
connecting to SQL Server 2005, this
failure may be caused by the fact that
under the default settings SQL Server
does not allow remote connections.
(provider: SQL Network Interfaces,
error: 26 - Error Locating
Server/Instance Specified)
There is a trust between the domains.
I tried the following with no success:
<add name="DbMaster" connectionString="Data Source=ServerName.DOMAIN.COM\NamedInstance;Initial Catalog=SomeDb;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>
I can ping ServerName.DOMAIN.COM.
I have tried connecting to the SQL Server on a different domain using SQL Server Management Studio but the same error as above is received.
Is there something obvious I am doing wrong?

If Management Studio is giving you the same error, the problem isn't with your application. The problem is with your SQL Server configuration.
Either the Trust between the Domains isn't properly configured to enable Integrated Security across domains or the SQL Server isn't properly configured to allow remote connections (like the error message states).
Integrated Security across domains is usually much more hassle than it's worth. Using SQL Server Authentication will relieve most of your headaches.

Related

IIS can't connect to SQL Server, but an external PC can

My VB.Net code connects to SQL Server. On my PC, it succeeds. On IIS running on the same machine as SQL Server, it fails. Any ideas?
I've tested:
I've tried IP address and server name. Same result.
I've tried Integrated Security and I've tried username/password. Same result.
On the server machine, Excel and SSMS can connect to SQL server using the same server name, username and password.
The fact that my PC can connect excludes many common problems including: ip address, server name, port, firewall, turn on sql server, connection string, credentials, permissions, sql roles.
Server (IIS and SQL) info: VB.Net, connection string providerName="System.Data.SqlClient", Windows Server 2008 SP2.
My PC info: Run website in Visual Studio 2019. Connects to same DB using same connection string (not local db and not as a different user).
Code (fails on second line):
oConn = ConnectionService.DatabaseName.Connect
oConn.Open()
Connection string: connectionString="Data Source=IP Address\SQLEXPRESS;Initial Catalog=DatabaseName;Integrated Security=False;Persist Security Info=False;User ID=Username;Password=Password;" providerName="System.Data.SqlClient"
Error message: System.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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) ---> System.ComponentModel.Win32Exception (0x80004005): The network path was not found
Oops. Right after posting this, I found out Web.Config pointed to a different connection string. That should explain and solve everything. I had checked Web.Config, but it turns out that that wasn't the one this server was using.

Why connection string is not working in production asp.net?

I am trying to connect my application with a database on the server for production but it is throwing an error like 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
In the web.config I had the connection string for development that worked perfectly but when I changed it for production, it is not working. Here is what I did:
<connectionStrings>
<add name="Vulosjet"
connectionString="Data Source=IP;Initial Catalog=Vulosjet;Integrated Security=false;User ID=********;Password=********" />
<add name="Vulosjet_app.Properties.Settings.VulosjetConnectionString"
connectionString="Data Source=IP;Initial Catalog=Vulosjet;Integrated Security=false;User ID=********;Password=********"
providerName="System.Data.SqlClient" />
</connectionStrings>
Any help please?
You're missing the providerName in your Vulosjet connection string.
Use only one connection name and you can change the content via your deployment method. Think of it as a variable with different values depending on where it's deployed. Read about "web.config transformations" to see how you achieve that.
Second, make sure that you can access the db server from your production environment.
Sort out these things and you'll be good to go.
There are many possible reasons:
Sql Server instance name is different (not MSSQLSERVER which is the default) - you would need to specify this in the server name e.g. 10.10.42.53/SQLProd or something
What protocols are configured for SQL on the Prod server? You may need to enable TCP/IP if you want to connect that way...
There is a firewall issue, either software on the SQL server in Prod or somewhere in the network in between the two.
There is a basic networking problem - there is no direct route for the PROD web server to talk to the PROD SQL server.
What this isn't (yet) is an authentication issue. it just can't see the server/instance

Azure Web Job SQL Connection String Server not found (On Prem SQL)?

I have a web app service in Azure with web job attached. The web App is connected to my company network via VNET in Azure but the webjob wont connect to the on premise sql instance.
here is the format of connection string I am using: which works locally through visual studio.
<add name="conn" connectionString="Server=192.0.0.0\SqlInstance;Initial Catalog=Database ;user id=xxx; password=xxx" providerName="System.Data.SqlClient" />
I am only trying to select some data at the moment to prove the concept but cant get it working.
I am 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)
I have check the sql instance and Allow Remote connections is enabled and firewall on the server is also disabled.
is my connection string wrong?
Thanks
I have found the problem - turns out our SQL instances are not using the standard ports. once I found out the correct port using SQL Config manager and applied it to the connection string it started working.
connectionString="Server=192.0.0.0\SqlInstance,5000;
Thanks to #Jason Haley for pointing me towards Kudu which helped me find the issue.

SQL Server Express connection string error

Trying to figure out the correct connection string for a SQL Server Express database. Trying to publish my app to IIS and test before publishing to my hosting site.
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 started here and also used connectionstrings.com. I also started reading the deploy asp.net app using SQL Server Compact article here
Using this connection string
Data Source=.\\SQLExpress;AttachDbFilename=H:\DB\Guestbook.sdf;Integrated Security=True
I get the above error
This connection string
<add name="DefaultConnection"
connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI; database=Guestbook; AttachDBFilename=|DataDirectory|Guestbook.sdf"
providerName="System.Data.SqlClient" />`
throws a trust level error. I've changed to medium and full and still get one of the two errors.
I've tried a variation of a few different strings with no luck.
Thanks
Please verify that SQL Service is started in services.msc and use the complete instance with the hostname ej: HOSTNAME\SQLEXPRESS
The file extension indicates that this is not a SQL Server Express database, so you must use:
Data Source=<Full path to file>
or
Data Source=|DataDirectory|Guestbook.sdf

provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified No fix?

I recently added a second site to my server. That site gives me the dreaded:
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 have no idea why I am getting this. I've gone through this and this to no avail. This is a new MVC4 application I have at beta.vinformative.com in IIS 7. The other site is a MVC3 site at vinformative.com. It is running fine. Both of their databases have the exact same connection string and they are both on the same SQL server. I've given the same user mapping and role membership for NT Authority\Network Service to both databases.
Here is what I've tried so far:
MSSQLSERVER SQL Server service is running along with SQL Server Browser, and SQL Server Agent
I've added a firewall inbound rule for SQL Server browser
Made sure TCP/IP is enabled in sql server configuration
Added port 1433 TCP to the firewall
Enabled remote connection to db server
Successfully pinged the machine
Used portqry to see the db server on UDP 1434
I can connect to the site locally when I am remotely logged into my server. Furthermore, I have an ELMAH instance in the application for error logging and that is updating the database correctly. I feel like I am taking crazy pills because this should be working and I can't find an outright error. Please help!
Here is my connection string
<add name="vfContext" connectionString="Data Source=vinformative;Initial Catalog=vf3;Integrated Security=True" providerName="System.Data.SqlClient" />
Could be EF - see here.
Also, remote access cannot work with "Integrated Security=True" as far as I know, should use "User ID=******;Password=****;Integrated Security=False".

Resources