locked
Which DB do I connect to RRS feed

  • Question

  • User-863795627 posted

    I have sql server express running on my machine.  I want to create a db connection using Empty Code First Model to this server.  Instead, Visual Studio (VS) creates a db to (LocalDb)\MSSQLLocalDB.

    Q1 - This DB is different from my SQL Server Express DB?  That is, when I connect to a DB on my sql express server I get the following connection string: data source=ASUS (Yes, I know, original naming ;-)  Basically, when I create an empty code first ADO.NET model it by default connects to its local version of local db correct?

    Once I'm done with the project, I'd like to be able to delete it, along with any/all DB info on Local DB?  How do I do that?  I don't know if SQL Server Express can connect to the LocalDB that comes with VS.  Do I connect to the LocalDB with VS or will the db info be deleted along with the project/solution?  I ask this, because after creating entries in LocalDB my App_Data folder has no mdf files???

    Thanks to all

    Tuesday, July 19, 2016 5:35 PM

Answers

  • User-359936451 posted

    I believe this is new to VS2013, I am still using 2012 but am starting to work on 2013 for new projects and have begun to deal with this.

    First off, yes you can connect to any version  of SQL Express with VS even for development work. You can google where the local DB is stored, but I believe it is in the app_data folder of your project folder. And yes it will be deleted the with the project when you delete the project.

    It does not matter which you do your development work with, other than the connect string needed to talk to each DB, look that up when you decided which to use. Though, if you add a control to a form and provide INSERT or basically CRUD operations to the DB, VS will build the connection string automatically.

    Hope this gets you started.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 19, 2016 6:33 PM
  • User-2057865890 posted

    Hi MarcinRak,

    Typically SQL Server Express is not used for production web applications. LocalDB in particular is not recommended for production use with a web application because it is not designed to work with IIS.

    Q1 - This DB is different from my SQL Server Express DB?  That is, when I connect to a DB on my sql express server I get the following connection string: data source=ASUS (Yes, I know, original naming ;-)  Basically, when I create an empty code first ADO.NET model it by default connects to its local version of local db correct?

    In Visual Studio 2012 and later versions, LocalDB is installed by default with Visual Studio. If you are using Visual Studio 2015, replace "v11.0" in the connection string with "MSSQLLocalDB", as the default SQL Server instance name has changed.

    <connectionStrings>
        <add name="SchoolContext" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=ContosoUniversity1;
    Integrated Security=SSPI;" providerName="System.Data.SqlClient"/> </connectionStrings> <appSettings> <add key="webpages:Version" value="3.0.0.0" /> <add key="webpages:Enabled" value="false" /> <add key="ClientValidationEnabled" value="true" /> <add key="UnobtrusiveJavaScriptEnabled" value="true" /> </appSettings>

    Once I'm done with the project, I'd like to be able to delete it, along with any/all DB info on Local DB?  How do I do that?  I don't know if SQL Server Express can connect to the LocalDB that comes with VS.  Do I connect to the LocalDB with VS or will the db info be deleted along with the project/solution?  I ask this, because after creating entries in LocalDB my App_Data folder has no mdf files???

    If you wanted the database to be created in your App_Data folder, you could add AttachDBFilename=|DataDirectory|\ContosoUniversity1.mdf to the connection string. 

    reference: Set up EF to use a SQL Server Express LocalDB database

    Best Regards,

    Chris

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 20, 2016 3:26 PM

All replies

  • User-359936451 posted

    I believe this is new to VS2013, I am still using 2012 but am starting to work on 2013 for new projects and have begun to deal with this.

    First off, yes you can connect to any version  of SQL Express with VS even for development work. You can google where the local DB is stored, but I believe it is in the app_data folder of your project folder. And yes it will be deleted the with the project when you delete the project.

    It does not matter which you do your development work with, other than the connect string needed to talk to each DB, look that up when you decided which to use. Though, if you add a control to a form and provide INSERT or basically CRUD operations to the DB, VS will build the connection string automatically.

    Hope this gets you started.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 19, 2016 6:33 PM
  • User-2057865890 posted

    Hi MarcinRak,

    Typically SQL Server Express is not used for production web applications. LocalDB in particular is not recommended for production use with a web application because it is not designed to work with IIS.

    Q1 - This DB is different from my SQL Server Express DB?  That is, when I connect to a DB on my sql express server I get the following connection string: data source=ASUS (Yes, I know, original naming ;-)  Basically, when I create an empty code first ADO.NET model it by default connects to its local version of local db correct?

    In Visual Studio 2012 and later versions, LocalDB is installed by default with Visual Studio. If you are using Visual Studio 2015, replace "v11.0" in the connection string with "MSSQLLocalDB", as the default SQL Server instance name has changed.

    <connectionStrings>
        <add name="SchoolContext" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=ContosoUniversity1;
    Integrated Security=SSPI;" providerName="System.Data.SqlClient"/> </connectionStrings> <appSettings> <add key="webpages:Version" value="3.0.0.0" /> <add key="webpages:Enabled" value="false" /> <add key="ClientValidationEnabled" value="true" /> <add key="UnobtrusiveJavaScriptEnabled" value="true" /> </appSettings>

    Once I'm done with the project, I'd like to be able to delete it, along with any/all DB info on Local DB?  How do I do that?  I don't know if SQL Server Express can connect to the LocalDB that comes with VS.  Do I connect to the LocalDB with VS or will the db info be deleted along with the project/solution?  I ask this, because after creating entries in LocalDB my App_Data folder has no mdf files???

    If you wanted the database to be created in your App_Data folder, you could add AttachDBFilename=|DataDirectory|\ContosoUniversity1.mdf to the connection string. 

    reference: Set up EF to use a SQL Server Express LocalDB database

    Best Regards,

    Chris

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 20, 2016 3:26 PM