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

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

Related

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

How can I change my connection string to point to SQL Server instead of SQLEXPRESS?

created a project with Web Developer Express 2012 using SQLEXPRESS as the database. I’ve deployed to a shared hosting site and I’m trying to use the connection string provided to me. I was given this:
Data Source=tcp:TheDatabase.com;Initial Catalog=TheNameOfTheDatabase;User ID=Username;Password=******;Integrated Security=False;
Here is how I’m using it:
<connectionStrings>
<add name="ApplicationServices"
connectionString="Data Source=. TheDatabase.com;Initial Catalog= TheNameOfTheDatabase;User ID=Username;Password=******;Integrated Security=False; ;User Instance=true"
providerName="System.Data.SqlClient" />
I get this error message:
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)
All the research I did points to my connection string trying to access an instance of SQLEXPRESS only I don’t see any where in my string where this is happening. How do I make it point to SQL Server instead of SQLEXPRESS?
Is there somewhere else in web.config that may need changing?
I know this would be easy to fix if I could use IIS to manage the database but my ISP is blocking port 1433 and I can’t connect directly to the site’s database. Very frustrating.
UPDATE"
I think my problem is in the Computername/Instance section of the string. Can someone please tell me which part of my string would be the computername and the server instance? On my local machine it is MyPcName/SQLEXPRESS or .\SQLEXPRESS.
UPDATE: Ok got an update from the winhost forum. I shouldn't be using the server_name/Instance_name anyway so I am at a lost.
So my project was using the default database (SQL Express) even though I didn’t have a connection string pointing to it. The EF uses convention to attach the default database if you don’t specify by using a constructor like this:
public class BloggingContext : DbContext
{
public BloggingContext()
: base("BloggingDatabase")
{
}
}
Then this:
<configuration>
<connectionStrings>
<add name="BloggingCompactDatabase"
providerName="System.Data.SqlServerCe.4.0"
connectionString="Data Source=Blogging.sdf"/>
</connectionStrings>
</configuration>
I found it all here…
http://msdn.microsoft.com/en-us/data/jj592674.aspx.

Network-related error in SQL Server

the following error appears when I want to launch the Security tab in ASP .NET Configuration site for my ASP NET MVC 4 project:
http://s14.postimg.org/jvizqragv/error_sql.png
I know that there are a lot of questions related to that error, but i tried a lot of the tips for solving this (I tried the suggested solutions here - http://blogs.msdn.com/b/walzenbach/archive/2010/04/14/how-to-enable-remote-connections-in-sql-server-2008.aspx but the error is still here).
But let me explain what are my databases in the solution. I have a local database (an .MDF file in App_Data) and a database for users authentication which was generated by ASP NET MVC. They are all placed in the App_Data folder as I'm trying to work on this solution on different machines. The strange thing is that on my laptop at home there is no such problem - I am able to create roles, explore users and all the functionality in the Security tab and I think there might be some problem with the SQL Server on my desktop machine - I use the Express edition on my laptop and the Developer edition on the other machine where things don't work.
My connection strings are the following:
<add name="FootballTransfers20130717145140Context" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\FootballTransfers.mdf;Integrated Security=True;MultipleActiveResultSets=True;Connect Timeout=30"
providerName="System.Data.SqlClient" />
<add name="DefaultConnection" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\DefaultConnection.mdf;Integrated Security=True;MultipleActiveResultSets=True;Connect Timeout=30"
providerName="System.Data.SqlClient" />
The first one is for the Entity framework and is related to the database where I store my application specific data. The second one is for the users administration database generated by SQL. Without the second connection string I'm not able to open any action of the Account controller.
It's very strange because it works on one machine and not on another. I was wondering if there's something wrong with the connection string, but I guess there's something with the SQL Server. As I said I tried various solutions but they didn't work.
LocalDB is a feature of SQL Server Express only. You will have to install SQL Server Express on the machine or import your database to your SQL Server and change your connection strings.
In production, you would probably have to move to a full SQL Server edition anyway.
I added the roles i was trying to make in code in the AccountController and now I'm able to register users with roles, but the problem that appeared now is that when I put the Authorize attribute on some action so that only users with certain roles can request them, the following error appears:
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)
When I remove the attribute so anyone can access it, the action works fine. I found some article on the net saying that providers must be specified in the config, but some errors kept appearing that those tags are unknown.

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".

SQL Server Connection String - Different Domain

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.

Resources