none
Database Issue RRS feed

  • Question

  • I recently hosted a website but the local database is not connecting. but when running my website on via visual studio on a local machine, everything works fine; the database connects and I am able to insert data into the database. since I hosted the site, the database does not connect.  Here is my connection string:

    con.ConnectionString = "Data Source (LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\Dataregister.mdf;Integrated Security=True";

    and this too:  SqlConnection con = new SqlConnection("Data Source (LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\Dataregister.mdf;Integrated Security=True"); I actually used these connection strings on different web pages.

    What will I do? 

    -Donald Uko

    Monday, April 6, 2020 8:23 AM

Answers

  • I recently hosted a website but the local database is not connecting. but when running my website on via visual studio on a local machine, everything works fine; the database connects and I am able to insert data into the database. since I hosted the site, the database does not connect.  Here is my connection string:

    Localdb  and the MDF and LDF files are not going to work when the Web solution is deployed to IIS, becuase Localdb is only for a single user instance that is mainly for software development.

    https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/sql-server-express-localdb?view=sql-server-ver15

    <copied>

    The system database files for the database are stored in the local AppData path, which is normally hidden. For example, C:\Users\<user>\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\LocalDBApp1\

    <end>

     The two files used by localdb the MDF and LDF files must be moved to a MS SQL Server server or an Express instance that has been installed on a computer moving them to the MS SQL Server Data directory where they will be Attached to the MS SQL Sever DB engine instance, becuase they are multi user database solutions suitable for a multi user Web program deployed to a Web server.. The single user instance Localdb is only for development.

    https://docs.microsoft.com/en-us/sql/relational-databases/databases/attach-a-database?view=sql-server-ver15


    Monday, April 6, 2020 9:25 AM

All replies

  • I recently hosted a website but the local database is not connecting. but when running my website on via visual studio on a local machine, everything works fine; the database connects and I am able to insert data into the database. since I hosted the site, the database does not connect.  Here is my connection string:

    Localdb  and the MDF and LDF files are not going to work when the Web solution is deployed to IIS, becuase Localdb is only for a single user instance that is mainly for software development.

    https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/sql-server-express-localdb?view=sql-server-ver15

    <copied>

    The system database files for the database are stored in the local AppData path, which is normally hidden. For example, C:\Users\<user>\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\LocalDBApp1\

    <end>

     The two files used by localdb the MDF and LDF files must be moved to a MS SQL Server server or an Express instance that has been installed on a computer moving them to the MS SQL Server Data directory where they will be Attached to the MS SQL Sever DB engine instance, becuase they are multi user database solutions suitable for a multi user Web program deployed to a Web server.. The single user instance Localdb is only for development.

    https://docs.microsoft.com/en-us/sql/relational-databases/databases/attach-a-database?view=sql-server-ver15


    Monday, April 6, 2020 9:25 AM
  • Hello,

    May I please have the steps taken to effect this change in the database to make it work on my hosted site?

    Thank you.

    -Donald Symmons

    Monday, April 6, 2020 11:37 AM
  • You will need to discuss with your web hosting provider the process needed to deploy the MS SQL Server Express database files to the provider's hosting platform.
    Monday, April 6, 2020 12:24 PM
  • Hi,

    Has your issue been resolved?

    If so, please click "Mark as answer" to the appropriate answer, so that it will help other members to find the solution quickly if they face a similar issue.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Donald Uko Tuesday, April 14, 2020 11:02 AM
    • Unmarked as answer by Naomi NModerator Tuesday, April 14, 2020 1:55 PM
    Tuesday, April 14, 2020 8:58 AM
  • Hello,

    Please reconsider the marked answer e.g. DA924x is the sole reply, if his reply solved the issue consider marking that reply as an answer. 


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, April 14, 2020 11:53 AM
    Moderator