sql server express connection string - sql-server

Is there a difference between sql server connection string and the express vesion?!

By default (though I don't recommend it1), Sql Express is installed as a named instance. That means you must connect like Server=servername.com\SQLEXPRESS as opposed to just Server=servername.com.
As always, connectionstrings.com has the goodies.
1 I don't recommend named instances because they run on a different port, which makes firewalling a PITA. Also, it makes little sense to me to run more than 1 MSSQL Server on a computer when you could just host multiple databases instead - so I'm not really sure what the point is.

Yes there is a difference- the big one being you won't have AttachDbFilename in the full SQL Server.
SQL Server Express connection string:
Server=.\SQLExpress;AttachDbFilename=c:\mydbfile.mdf;Database=dbname; Trusted_Connection=Yes;
Typical normal SQL Server connection string:
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;
See connectionStrings.com for more info.

The connection string used to access SQL Server and SQL Server Express?
Generally, no. That's the nice thing about using Express; develop with it locally and with minimal changes migrate your data access to SQL Server.

The only difference is that you'll have to specify a named instance in the conn string, if Express was setup that way. 2005 had no option, but 2008 does.
Data Source=localhost\SQLExpress
Here's a great reference for connection strings.

I recently downloaded a sample application from the Telerik site and could not get it to run on my machine that has only SQL Server 2008 SP1 Developer Edition installed until I did a find and replace of all "User Instance=True" with "User Instance=False".
Before anybody goes and gets their panties all twisted in a knot, hear me out first. My circumstances may be (but ought not be) unique in that instead of installing SQL Server 2008 Express just to run example applications (e.g., Telerik), I simply installed a second named instance of SQL Server named, you guessed it, sqlexpress on my copy of SQL Server 2008 Developer Edition. That way when the Telerik (or you name it) demo application tries to connect to "Data Source=.\sqlexpress", it's none the wiser that what it's really connecting too is "big SQL Server" (which is what SQL Server Developer Edition is for the purposes of this posting).
The key conecpts (dare I say "money quote") you need to understand are these:
SQL Express allows (actually assumes if missing) User Instance=True, so if you are running a named instance called sqlexpress on "big SQL" (Developer, Standard, Enterprise or Data Center), then you just need to find/replace User Instance=True with User Instance=False in the connecton string and your worries are over. Even the "Attach database" stuff (that I see in the Telerik connectionStrings section of their web.config) works on "big SQL" (contrary to what somebody posted earlier in this thread).
Here's an actual example taken directly from the web.config of the Telerik web.config file after I "fixed it up":
<connectionStrings>
<add name="NorthwindConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|Northwind.mdf;Integrated Security=True;User Instance=False" providerName="System.Data.SqlClient"/>
<add name="TelerikConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|Telerik.mdf;Integrated Security=True;User Instance=False" providerName="System.Data.SqlClient"/>
<add name="NorthwindConnectionString35" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|Northwind.mdf;Integrated Security=True;User Instance=False" providerName="System.Data.SqlClient"/>
<add name="TelerikConnectionString35" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|Telerik.mdf;Integrated Security=True;User Instance=False" providerName="System.Data.SqlClient"/>
<add name="NorthwindEntities" connectionString="metadata=res://*;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Northwind.mdf;Integrated Security=True;User Instance=False;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient"/>
<add name="TelerikEntities" connectionString="metadata=res://*;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Telerik.mdf;Integrated Security=True;User Instance=False;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient"/>
<add name="EditorFileBrowserDatabase" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|EditorDBStorage.mdf;Integrated Security=True;User Instance=False" providerName="System.Data.SqlClient"/>
</connectionStrings>

In addition to previous post: If you have troubles with setup Telerik samples on MSSQL Server 2008, you can do the following:
Open LiveDemos Telerik VS solution
Setup database connections for telerik .mdf files in VS master
Copy connection string for connections to the web.config file
And add "Integrated Security=True;User Instance=False" to the end of the strings.
PS. Fred Morrison - thanx, you are my "man of day", I just fix Telerik Live Demo problem with you post help!

Related

How to transfer ASP.NET MVC Database from LocalDb to SQL Server?

I created a new ASP.NET MVC 5 project in Visual Studio 2013 (Express for Web) and by default, the project uses LocalDb as its database, but how do you transfer or migrate the database to SQL Server?
I want to use SQL Server for the database instead of LocalDb. But how?
Notwithstanding this question is old, the answer didn't help me so I want to share how I solved it for my self.
On Server Explorer, find your ASPNet DB. Then open it using SQL Server Object Explorer.
Then go and hit Schema Compare option
Then on the the Schema Compare window for the Target database, select the SQL Server data base you want the ASPNet DB to integrate to. Then hit Compare button
Deselect all Delete actions for the target database, and leave selected all Add actions for the ASPNet DB, then hit Update button.
Finally, update your connection string so it points to your SQL Server DB
Got it!
Based on #warheat1990's answer, you just have to change the connection string. But #warheat1990's answer had a little too much change. So here's my original (LocalDb) connection string:
<add name="DefaultConnection"
connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-my_project-20150318100658.mdf;Initial Catalog=my_project-20150318100658;Integrated Security=True"
providerName="System.Data.SqlClient"/>
To connect it to SQL Server instead of LocalDB, I modified the connection string into:
<add name="DefaultConnection"
connectionString="Data Source=SERVERNAME\SQLEXPRESS;Initial Catalog=my_project;Integrated Security=True"
providerName="System.Data.SqlClient"/>
Thanks to #warheat1990 for the idea of simply changing the Web.config. My first thoughts were to identify and use the feature that VS supplies, if theres any. Because Microsoft doesnt have a concise documentation on how to do this.
Change the connectionString in your web.config
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-KlikRX-20141203034323.mdf;Initial Catalog=aspnet-Test-20141203034323;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
to your own database connectionString, for example :
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=7.7.7.7\sql;Initial Catalog=TestDB;User ID=sa;Password=sa" />
</connectionStrings>
It sounds like you may want to move the data from your local database to sql server. If so, the easiest way to do this would be to back up your local database and then restore it on the server.
To back up:
https://msdn.microsoft.com/en-us/library/ms187510.aspx#SSMSProcedure
To restore:
https://msdn.microsoft.com/en-us/library/ms177429.aspx
EDIT:
If you need to install an instance of SQL Server:
https://msdn.microsoft.com/en-us/library/ms143219.aspx
Overlord's migration example is spot on. My note at the end was a bit big for a comment, so here are the required changes to the web.config file. An old method on a local drive was to specify
Data Source=".\[InstanceName]
but may not work on newer interfaces, so replace [.\instance] with [ComputerName\instance] if you migrate forward. This is Visual Studio Pro 2017, SQL Server 2014 & Entity Framework 6.0.
1st update the connection string.. replace items in brackets with info needed to connect to your database.
<connectionStrings>
<add name="DefaultConnection"
connectionString="Initial Catalog=[DatabaseName];Integrated Security=True;User ID=[SQLASPNETUserName];Password=[UserPassword];"
providerName="System.Data.SqlClient" />
</connectionStrings>
next update the entity info.. The [InstanceName] used for SQL Server can be found from [SQL Server Mgmt] console - [Server Properties] - [Advanced] - [Filestream Share Name] & defaults as [MSSQLSERVER].
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="[ServerName]\[InstanceName]"/>
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient"
type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
</entityFramework>
for cloud or other multi-server database migrations, also review [sessionState] settings in web.config & replace [InProc] with [Custom]. [sessionState] comes between [/roleManager] & [/system.web]
this default for 1 db server
<sessionState mode="InProc" customProvider="DefaultSessionProvider">
<providers>
<add name="DefaultSessionProvider"
type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
connectionStringName="DefaultConnection"/>
</providers>
</sessionState>
& this replacement for mult-server or cloud environments
<sessionState mode="Custom" customProvider="DefaultSessionProvider">
I had the same problem and just solved this...so the main point is default connection string...which you need to modify correctly otherwise it is pointless..and impossible to connect properly. So copy all you aspnetroles...users table to online database( they should look the same as in your local database).
You can compare schema(local db) with real db. It is quit well explained by "Overlord" -> Explanation
But after lets now correctly modify defaultconnection string
That is my default string before modification:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-track_spa-20180502025513.mdf;Initial Catalog=aspnet-track_spa-20180502025513;Integrated Security=True" providerName="System.Data.SqlClient" />
That is my modified default string after modification:
<add name="DefaultConnection" connectionString="Data Source=servername,portnumber;Initial Catalog=AttendanceTrak;Integrated Security=False;User Id=****;Password=*****;Encrypt=True;TrustServerCertificate=False;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
servername - should be your server.
portnumber - should be your server port
It took me ages to finally get it working properly...but this small trick with default string just made it!
Hops this helps
In relation to OverLords answer, it worked perfectly for me thanks!
If anyone is struggling with the connection string use:
<add name="CONNECTIONSTRINGNAME" connectionString='data source= DATABASE SOURCE initial catalog="DATABASE NAME ";user id="USERID";password=PASSWORD;MultipleActiveResultSets=True;' providerName="System.Data.SqlClient" />
I had a similar problem, wanting to export from a local db to remote db-server and encountered an error message I couldn't find any information on, but the answer came to me when reading this post, so I'm submitting my answer here in case anyone else has the same problem.
I set up a solution with Individual User Accounts. VS conveniently creates a db (mdf-file under App_Data) and a connectionstring in the web.config.
In all my wisdom I thought: "Why not move this to a remote server?" So I did.
I restored the mdf file on the remote server, expanded it with some simple tables for my web site, created a new connection to the db and added a new ado.net edmx-file, removed the "DefaultConnection" in the web.config and updated the reference to my new connection in the ApplicationDBContext.
Pressed play, and... no sigar (when trying to log in).
The entity type IdentityUserLogin is not part of the model for the current context.
Turns out the IdentityDbContex prefers the "DefaultConnection" with the providerName="System.Data.SqlClient" so adding a new edmx-file with the providerName="System.Data.EntityClient" is no good.
Solution: As warheat1990 suggested, I updated (put back) the DefaultConnections and it's connectionstring value.
One might argue that I should have two seperate db's (one for users) and one for business stuff, but that's an other discussion.
This works for me..
Change the connection string in the web config file pointing to the database server, then run the application and register a user. Once registered successfully, go to SSMS and refresh the database and then the identity tables should appear.
Regards

Cannot create a local sql server 2012

I am trying to create a database for an MVC 4 application. I used Entity Framework Code first approach. After digging into the problem I realized that it was not a connection string issue. I downloaded Sql Server Data tools and tried to create it from there but I get the same exact error which is related to Windows Authentication. I am not sure what is causing this problem, I even tried running as admin.
Any ideas??
I have tried mostly all forms of connections strings available online, the last two that I tried were
<add name="Request" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=Requests;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\Requests.mdf" providerName="System.Data.SqlClient" />
<!--<add name="RequestsContext" providerName="System.Data.SqlServerCe.4.0" connectionString="Data Source=|DataDirectory|\Requests.mdf" /> -->
I am trying to create a local database, I have asked a question about entity frame work right here thinking that the problem was from there but now I know it has nothing to do with it. Here you can see all of the details about the models I created and I am trying to generate the database from.
Using Entity framework with SQL Server 2012 (local *.mdf database)
You don't have SQL Server installed on your PC. Install Express Edition and you should be fine.
EDIT: Use connection string for local server:
<add name="Request" providerName="System.Data.SqlClient" connectionString="Server=.\SQLEXPRESS;Database=Request;Integrated Security=True;" />
If its local, probably SQL Server service is not running. Start>cmd and services.msc will open services page. Right click on sql server and start

connection string is not working with my database on Microsoft SQL Server in ASP.NET MVC 4

I have this on my web.config file
<add name="EFDBContext"
connectionString="Data Source=(localdb)\v11.0;Initial Catalog=StadinPeli;
Integrated Security=True"
providerName="System.Data.SqlClient"/>
And yes in Server Explorer in visual studio 2012 professional edition, it works with
EFDBContext (WebUI).
But its the wrong database. Somehow this EFDBContext database copy its definitions from the database where I want it to connect all the time,
which is jon-pc\localdb#13158683.StadinPeli.dbo.
I checked properties from jon-pc\localdb#13158683.StadinPeli.dbo for its connection string
but it still connects to EFDBContext (WebUI).
Where is the problem, I have tried to correct this for 3 hours already.
(Localdb) as data source is probably wrong. Try updating it to (local) so your connection string looks like this
<add name="EFDBContext"
connectionString="Data Source=(local)\v11.0;Initial Catalog=StadinPeli;
Integrated Security=True"
providerName="System.Data.SqlClient"/>

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.

how to setup MVC application to use sql server 2008 r2 express

I am trying to follow the tutorial on the building my first MVC application for here
all was good until I needed to run the application an entity framework should have done it's thing and create the data base for me, but for some reason I always get the same error :
The provider did not return a ProviderManifestToken string.
my question:
what are the necessary adjustments i need to do in order for the application to work?
here is my web.config file connection string section
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=Moran-Laptop;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
<add name="MovieDBContext"
connectionString="Data Source=|DataDirectory|Movies.sdf"
providerName="System.Data.SqlServerCe.4.0"/>
I think your data source is not correct. Does it work with:
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
If you inspect the exception you will find out that there is InnerException as well which most probably points to SqlException and its inability to find the database or server. Your ConnectionString expects that you have Sql Server CE database available in your App_Data folder. The tutorial that you are looking does not yet tell you that you have to add a new SQL Server CE database to your App_Data folder. Check part 5 of the tutorial http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/getting-started-with-mvc3-part5-cs
First off you need to change your connection strings to point to the servers instance of sql server rather than to your laptop
in your connection strings replace Moran-laptop with "server-name\db name" i.e. r2008sqlserver\movies

Resources