Sql Connection String to named instance - sql-server

I can connect to my sql server 2008 developer server using this in a sample code project:
string connection = #"data source=.\SQLSERVER2008;Integrated Security=SSPI;Initial Catalog=RSINET.MVC";
When I try updating the web.config file like so, I get a sql exception:
<add name="ApplicationServices" connectionString="data source=.\SQLSERVER2008;Integrated Security=SSPI;Initial Catalog=RSINET.MVC" providerName="System.Data.SqlClient"/>
The error that I get is this:
Verify that the instance name is correct and that SQL Server is configured to allow remote connections.
I am using the .NET provider?
matt

Did you try using LOCALHOST\SQLSERVER2008 or 127.0.0.1\SQLSERVER2008 or \SQLSERVER2008? Also why is there a period in your database name? You will likely have to escape that (or preferably get rid of it by changing the name)... even if it doesn't solve this issue, it will cause others if you leave it that way.

Configure your server for remote connections
http://support.microsoft.com/kb/914277

Add the port (default 1433) to the connection string.
Ie: localhost\SQLSERVER2008,1433

Related

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

Why is my connection to a local SQL Server db failing?

Based on what I learned here, I'm using this connection string:
using (var conn = new SqlConnection(#"AttachDBFilename=C:\HoldingTank\AdventureWorksLT2012_Database\AdventureWorksLT2012_Data.MDF;Integrated Security=True;User Instance=true"))
...to (attempt to) attach to a local SQL Server db, but I get this exception at runtime:
System.Data.SqlClient.SqlException was unhandled by user code
HResult=-2146232060
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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Source=.Net SqlClient Data Provider
Based on my legacy MS Access connection string, I had previously also had:
Provider=System.Data.SqlClient;
prior to the "AttachDBFilename=..." part of the connection string, but that caused an exception of its own...
You are missing a few values in the connection string. Here is one I used recently:
"Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\mydbname.mdf;Initial Catalog=mydbname;Integrated Security=True"
I'm thinking the most likely culprit is the lack of the "Initial Catalog" value.
The connection string you need will depend on several factors, such as the edition of SQL Server (LocalDB/Express/Standard), whether or not it's a named instance, and the type of authentication (SQL vs Integrated) you have in place.
The answer from #zippit is a good example of a connection string for LocalDB using integrated security.
The same string to a Sql Express server would look like this:
"Data Source=serverNameOrIpAddress\sqlepxress;AttachDbFilename=|DataDirectory|\mydbname.mdf;Initial Catalog=mydbname;Integrated Security=True"
..and to a standard edition of Sql Server would look like this:
"Data Source=serverNameOrIpAddress\sqlepxress;AttachDbFilename=|DataDirectory|\mydbname.mdf;Initial Catalog=mydbname;Integrated Security=True"
..and to a named instance on a standard edition of Sql Server would look like this:
"Data Source=serverNameOrIpAddress\instanceName;AttachDbFilename=|DataDirectory|\mydbname.mdf;Initial Catalog=mydbname;Integrated Security=True"
All those assume integrated authentication. If you have sql authentication set up, you would substitute "Integrated Security=True" with "User Id=username; Password=pword;"
Also, if the sql server is on the same machine, you can use this for the Data Source parameter for Sql Express
.\sqlexpress
..and this for standard Sql Server
(local)
Here's a site I've found useful: Connection Strings

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.

Cannot connect to Database with Entity Framework

Every time I have a fresh install of Windows, Visual Studio and Sql Server I always have problems getting an application to connect to the local instance of Sql Server.
I am trying to start an application using Entity Framework code first. Here is my connection string.
<add name="KCSoccerDataContext"
connectionString="Data Source=.\MSSQLSERVER;Initial Catalog=KCSoccer;Integrated Security=SSPI"
providerName="System.Data.SqlClient" />
I am able to connect to the database instance using Sql Server Management Studio, but can't seem to connect using this connection string. I am assuming the problem has to do with how the database instance is configured.
The error I'm getting is
{"The provider did not return a ProviderManifestToken string."}
I'm not exactly sure what this means or where to go from here.
Any help anyone could give on this would be awesome.
Thanks
Use just this connection string:
<add name="KCSoccerDataContext"
connectionString="Data Source=.;Initial Catalog=KCSoccer;Integrated Security=SSPI"
providerName="System.Data.SqlClient" />
MSSQLSERVER is name of default instance. It is not used in connection strings. It even doesn't work from Management studio if you try using it. Only names of custom instances must by used.
You probably didn't enable remote connections for SQL Server since it's a fresh installation. Follow first solution here or here.

Converting Entity Framework connection string to SQL Server Express

My project has an Entity Framework connection string but I want to connect to a SQL Server Express database, so I think I have to change the connection string to SQL Server Express - but how ?
I want to change below connection string. Is it also enough connect database just changing connection string for same SQL Server mdf file ?
<add name="MyEntities"
connectionString="metadata=res://*/Model.MyEntities.csdl|res://*/Model.MyEntities.ssdl|res://*/Model.TravldbEntities.msl;
provider=System.Data.SqlClient;
provider connection string="Data Source=sandiego;
Initial Catalog=mydatabse;Persist Security Info=True;
User ID=user;Password='password';MultipleActiveResultSets=True""
providerName="System.Data.EntityClient" />
What have you tried? I'm not familiar with EF, but why not just try something similar to how a normal C# app would connect:
<add name="MyEntities"
connectionString="provider=System.Data.SqlClient;
Data Source=sandiego; -- maybe needs to be sandiego\SQLEXPRESS?
User ID=user;
Password=password;">
I would only specify the MARS attribute if you know for sure you need it.
Instead of this:
Data Source=sandiego
Use this:
Data Source=SomeMachineNameOrIP\SQLExpress
Here's another similar answer.

Resources