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

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.

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

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

Connection string between IIS and SQL server

I'm confused by the connection string in the Web.config file of project with Entity Framework Web API. There are a lot of variants I tried, but none of them was helping me out. Currently the connection string is
<connectionStrings>
<add name="DefaultConnection" connectionString="Server=.\SQLEXPRESS;Database=MyProject;User Id=John;Password=duck;" providerName="System.Data.SqlClient" />
</connectionStrings>
I can access the database which is called MyProject in SQL Server Management Studio 2012 (even from remote), using John as username and duck as password.
The project is run by an IIS server on the same machine as the SQL server, the SQL server's instance name is SQLEXPRESS.
My webpage is displayed on localhost, but the controller just replies 500 Interal server error whenever some data from the sql database is requested. It looks like there is no connection to the database.
What do I have to add or change in order to get a connection betweeen IIS and SQL server, or how can I locate better the problem's cause?
Use the Event Viewer to get more information on what the 500 error actually is.
This tutorial how to setup SQL Server 2008 for an ASP.net website on IIS 7.0 brought me close to the solution.
Basically, what you need to do is
Install SQL server.
Allow TCP/IP connections to the SQL server.
Attach your database.
Create a login. I'm using SQL Authentication.
Assign the user permissions to your database.
Configure your database connection string.
Changing the name of my connection string helped me establish the connection finally.
<connectionStrings>
<add name="MyProjectContext" connectionString="Server=.\SQLEXPRESS;Database=MyProject;User Id=John;Password=duck;" providerName="System.Data.SqlClient" />
</connectionStrings>
The context model required this name.
public class MyProjectContext : DbContext
{
public MyProjectContext() : base("name=MyProjectContext")
{
}
public DbSet<Model1> Model1 { get; set; }
public DbSet<Model2> Model2 { get; set; }
}
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=MyProject;User ID=John;Password=duck" providerName="System.Data.SqlClient" />
</connectionStrings>
Please try the above connection syntax.
Basically just amend your connection string using Integrated Security=False like :
and it will work ...
My answer is not related to connection string, however, if you have an application that is hosted on IIS and it tries to connect to SQL Server and you get "500 Interal server" error (despite a correct connection string), you still need to configure both IIS and SQL Server.
There is an invaluable article called "Configuring IIS, ASP.NET, and SQL Server".
I followed the steps described there and my app communicates with my SQL database fine now:
https://www.codeproject.com/Articles/674930/Configuring-IIS-ASP-NET-and-SQL-Server

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.

Sql Connection String to named instance

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

Resources