I am using MVC 5 and the default authentication built in using the Live\Microsoft sign on.
It appears that the site is firing up SQLExpress targeting a folder in %appdata% as the directory.
Here is my connection string:
Data Source=.\SQLEXPRESS;Initial Catalog=mydb;Integrated Security=True;User Instance=True
Why wouldn't it just use the instance of SQLExpress that is already running. For whatever reason I can't connect sql studio to this private instance of sqlexpress which makes it rather frustrating.
How do I get it to stop?
Silly me. The "User Instance=True" part of the connection string was doing it.
Related
I am following the Mvc4 OdeToFood tutorial on Pluralsight, which uses asp-net Mvc4 and visual studio express for web 2012.
I am trying to set up a small local database to hold some information so that I can proceed with the tutorial, but I am having trouble getting the database versions and connection string right, I have never done anything like this before.
I have been going fine until a few days ago when I tried to connect to a Local database.
Unlike in the tutorial, In my web.config file I had no connection string tags, The v11.0 database instance was specified in the tutorial, which from google seems to be a local database used for development purposes. so I looked up what I needed and entered into the Web.config file:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=
(LocalDb)\v11.0;Initial
Catalog=OdeToFoodDb;Integrated
Security=SSPI;AttachDBFilename=|DataDirectory|\OdeToFoodDb.mdf"
providerName="System.Data.SqlClient" />
</connectionStrings>
This would not work for me, so upon more googling I tried:
<connectionStrings>
<add name="OdeToFood" connectionString="Data Source=
(LocalDb)\MSSQLLocalDB;Initial
Catalog=aspnet-OdeToFood;Integrated
Security=SSPI;AttachDBFilename=|DataDirectory|\OdeToFood.mdf"
providerName="System.Data.SqlClient" />
</connectionStrings>
This initially did work, but when I tried to modify the tables, there was a database version error and I could not use the database crud functionality with the program. I searched as to why this wouldn't work and looked through the error files and I found that once you change a .mdf file to v13.0 (from googling I believe MSSQLLocalDB is v13.0) it cannot be reverted to a v11.0 .mdf version. So I guess vs express 2012 can only use v11.0?
If anyone can help me or point me to somewhere where I can learn how to connect to this database I would be really grateful.
I created a new ASP.NET web application in VS2017 as blank and installed Entity Framework in it and all important libraries.
Problem is:
I successfully ran Enable-Migrations
I successfully ran Add-Migration Initialize
But I can't execute update-database because I can't connect to SQL Server Express just from this project
I tried to open other project and it fork very fine
I think there is a problem in the web.config file because I start from scratch
I add a connection string as follows:
<connectionStrings>
<add name="DefaultConnection"
connectionString="Server=OJ-PC\OJ_SQLEXPRESS;Database=OrdersDb;User Id=sa;Password=******;"
providerName="System.Data.SqlClient" />
</connectionStrings>
I tried a lot of connection strings. I get connection string from SQL Server and add it exactly. I tried same connection string that worked in other project but it didn't work in this project.
In two days I tried everything
Thanks for help!
The . (dot) alias is used when you deal with SQL Server Professional edition.
When it comes to dealing with SQL Express the server name consists of 2 parts separated by backslash \.
For instance
DESKTOP-3PQ45JH\SQLEXPRESS
In this case DESKTOP-3PQ45JH is the name of computer, SQLEXPRESS is the name of server instance.
I have 2 connection strings - 1 local and 1 for my main production server. Entity Framework added App=EntityFramework to my local string when I installed it (4.1) - I'm now on 4.3. What does this do - I can't find any reference to it?
Here's my local connection string:
<add name="LocalConnection"
providerName="System.Data.EntityClient"
connectionString="metadata=
res://*/;
provider=System.Data.SqlClient;
provider connection string='
Data Source=.\SQLEXPRESS;
AttachDBFilename=C:\mypath\MyDb.mdf;
Integrated Security=True;
User Instance=True;
MultipleActiveResultSets=True;
App=EntityFramework'" />
Just curious!
App and Application Name are simply a way for somebody debugging SQL Server to know which client is connecting to it. If you had a SQL Server that has several apps that used it, it might be hard to know which one was sending which statements. If each app used a different Application Name it would be very clear.
Check this out for more info.
It's just the synonym of the Application Name.
You can see the Connection String properties outlined here:
http://msdn.microsoft.com/en-gb/library/system.data.sqlclient.sqlconnection.connectionstring.aspx
I was trying the ASP.Net MVC 4 tutorial. When I have added the following code and build the application I was expecting Movies.mdf file will be created under App_Data folder on the Solution Explorer. However, nothing has been created in that directory. Any idea why?
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-MvcMovie-2012213181139;Integrated Security=true"
providerName="System.Data.SqlClient"/>
<add name="MovieDBContext"
connectionString="Data Source= (LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Movies.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
Using:
.NET Framework 4
VS 2010
Having a full instance of MS SQL 2012 on my machine, not SqlExpress, I had this problem. I found that by letting the application continue (instead of halting it in visual studio when VS catches the exception) I got a helpful message in the browser:
Directory lookup for the file "c:\users\chris\documents\visual studio
2012\Projects\MvcApplication1\MvcApplication1\App_Data\aspnet-MvcApplication1-20140225162244.mdf"
failed with the operating system error 5(Access is denied.). CREATE
DATABASE failed. Some file names listed could not be created. Check
related errors.
which tells that the problem is that the sql service doesn't have write permissions to my application directory.
Giving it permissions was slightly tricky because the username needed didn't come up (in Windows 8 Pro) in the Explorer GUI for Security. The username for a Default Instance of Sql Server is NT SERVICE\MSSQLSERVER (for an instance it's NT SERVICE\MSSQL$InstanceName) and I had to type it in by hand, and then give it write permissions. I did this just on the App_data directory.
Then it worked.
The problem is solved. The problem was the location of the project. I was working with the files from a shared drive which apparently did not create the database in the App_Data folder. Connectionstring code is absolutely fine as it is shown in the tutorial and no changes are required.
The database will not be created before you actually add the first record to one of your tables.
This error occurs when Visual studio and MSSQL are running under different authorities. For this reason, your application doesn't get to have a write permission for creating the .mdf database file.
SOLUTION
Open SQL Server Configuration Manager
Select SQL Server Services
See the Log On As tab
the value would be something like NT AUTHORITY\NETWORKSERVICE ( it depends )
Once you get the user name,
then go to the target folder. ( If default, App_Data in your project directory )
right click -> property windows -> security tab
click edit -> check the user or group name
You shall not see there's no Network Service on the user or group name list
All you have to do is to add the user name and give the write permission for that user or group.
It may be the case of AttachDBFilename... I have this for my project and it works fine.
... connectionString="Data Source=(LocalDb)\v11.0;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|Movies.mdf" providerName="System.Data.SqlClient"
Also verify your model is correct. If your model does not initiate this connection then it will not create the database.
I have resolved the issue by modifying the connectionstring like below
<add name="MovieDBContext"
connectionString="Data Source=.;Initial Catalog=Movies;AttachDbFilename=|DataDirectory|\Movies.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
I did install Microsoft SQl Server Compact 4.0 from nuget.. but I am not sure whether it is really require to install it or not.
In this MVC tutorial, just add "Initial Catalog=Movies;" (without quote) to the connection string and it'll work well.
<add name="MovieDBContext" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=Movies;AttachDbFilename=|DataDirectory|\Movies.mdf;Integrated Security=True" providerName="System.Data.SqlClient"/>
I was able to create an application in VB.net that talks to a SQL Server CE database.
Now i want to deploy this application using the publish feature with clickonce.
An issue im having tho is when I install the application on another computer it keeps looking for my sql server on my development pc.
Ive added the .sdf when i package my solution but its still an issue.
How do I change my connection string to connect to the .sdf file that I included in the package?
this is my current connection string which looks at the sql server:
connectionString = " Data Source=CHRIS-PC\SQLEXPRESS;Initial Catalog=ce_db;Integrated Security=True"
Thanks !!
connectionString = "Data Source=localhost\SQLEXPRESS;Initial Catalog=ce_db;Integrated Security=True"
or perhaps
connectionString = "Data Source=" + (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\ce_db.sdf;Persist Security Info=False;";
this connection string would work if you had the database in the same directory as the executable using it.
essencially the data source is either the database server that you are connecting to, or the database file that you are connecting to.
If you are using a file then you have only one catalog. and if you are using a server then you will want to specify a specific catalog using the Initial catalog attribute of the connection string.