Converting Entity Framework connection string to SQL Server Express - sql-server

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.

Related

How to create the Data Source property of the ConnectionString in ASP/net MVC?

I can't find a decent tutorial/blog that has a solution for my problem.
On my laptop I run a Microsoft SQLServer named 'SQLSERVER'. There's a database in it called 'SalesDB'. I can't figure out how to fill in the Data Source property of the ConnectionString in the web.config file in my ASP.NET MVC 4 application to get my application connected with the database.
This is the default connectionstring:
<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-Labo7SQL-20131226161445;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-Labo7SQL-20131226161445.mdf" />
connectionstrings.com tends to be a pretty useful resource for formatting a connection string. For MS SQL Server, you have a few options. Such as:
Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;
or
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
or
Server=myServerName\myInstanceName;Database=myDataBase;User Id=myUsername;Password=myPassword;
Using the last one as an example, yours might be something like:
Server=localhost\SQLSERVER;Database=SalesDB;User Id=myUsername;Password=myPassword;
The Data Source value should be the name (or ip address) of your sql sever. The Initial Catalog value should be the name of your database...SalesDB and you should remove the AttachDBFilename

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.

EntityFrame work connection string issue

I am working on a Silverlight application. during development I have been working with a copy of our production database on my local machine.
When setting up the project I created a model of the local database, and then created a domain service of that model to interact with the data. This is all working well. Now I need to test my product against the live server, but I can not seem to figure out the connection string.
Currently the connection string looks like this.
<add name="UserDataEntities" connectionString="metadata=res://*/Models.UserDataModel.csdl|res://*/Models.UserDataModel.ssdl|res://*/Models.UserDataModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=RTRP20112_NATP_UserData;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
The only differance between the database I have been using locally, and the production database is its location. I have attempted to simple replace the data source portion of the connection string with the correct address, and login info but that does not work. I have also duplicated the connection string used by another application to connect to this database, but that does not work since it is missing all the metadata junk(i think). I am not sure how to proceed.
The connection string used by other programs to connect to the server is
<add name="UserDatabase" connectionString="Data Source=*.*.*.*,*;Network Library=DBMSSOCN;Initial Catalog=RTRP20112_NATP_UserData;User ID=*;Password=*;" providerName="System.Data.SqlClient"/>
I have tried a few variations of the two as a connection string, most recently I am using.
<add name="UserDataEntities" connectionString="metadata=res://*/Models.UserDataModel.csdl|res://*/Models.UserDataModel.ssdl|res://*/Models.UserDataModel.msl;provider=System.Data.SqlClient;provider connection string="data source=*.*.*.*,*;Network Library=DBMSSOCN;Initial Catalog=RTRP20112_NATP_UserData;User ID=*;Password=*;App=EntityFramework"" providerName="System.Data.EntityClient" />
The most recent error is: Load Error
System.ServiceModel.DomainServices.Client.DomainOperationException:Load operation failed for query 'GetUsers'. The undelying provider failed on Open.
Have you configured/created ASPNETDB ?

Problem accessing database for Entity Framework

I've created a windows forms application that would use a client server model for accessing database. I created a connection for Entity Framework Model and it works fine with the following connection string:
connectionString="metadata=res://*/CartonOrderModel.csdl|
res://*/CartonOrderModel.ssdl|
res://*/CartonOrderModel.msl;
provider=System.Data.SqlClient;
provider connection string="
Data Source=.\SQLEXPRESS;
AttachDbFilename=E:\Databases\RollMeasurements.mdf;
Integrated Security=True;
Connect Timeout=30;
User Instance=True;
MultipleActiveResultSets=True""
providerName="System.Data.EntityClient"
I wonder if this connection string would still work when i deploy it on client environment which has a central db server and more than one instance of my app would be accessing it from client machines.
I tried changing the connection string to this:
connectionString="metadata=res://*/CartonOrderModel.csdl|
res://*/CartonOrderModel.ssdl|
res://*/CartonOrderModel.msl;
provider=System.Data.SqlClient;
provider connection string="
Data Source=.\SQLEXPRESS;
Initial Catalog=RollMeasurements;
User ID=sa;
Password=sapassword;
Connect Timeout=30;
User Instance=True;
MultipleActiveResultSets=True""
providerName="System.Data.EntityClient"
But now when I run my app it gives me this exception:
Failed to generate a user instance of SQL Server. Only an integrated
connection can generate a user instance. The connection will be
closed.
Please help me with this. Thanks!
I think you have to remove User Instance=True (or set it to False explicitely). User Instances are local copies of a SQL Express database and not suited for work in a multiuser environment with a central DB.
I think if you want to access to a central server, you need to change the Data Source=.\SQLEXPRESS; line to a central sql server instance.
english is not my mother language so maybe dont understand correctly the question.
Cheers

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