Connecting to local SQL Server database using C#

前端 未结 6 1851
后悔当初
后悔当初 2020-12-17 16:53

Suppose I have created a SQL Server database called Database1.mdf in the App_Data folder in Visual Studio with a table called Names. <

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-17 16:57

    If you're using SQL Server express, change

    SqlConnection conn = new SqlConnection("Server=localhost;" 
           + "Database=Database1;");
    

    to

    SqlConnection conn = new SqlConnection("Server=localhost\SQLExpress;" 
           + "Database=Database1;");
    

    That, and hundreds more connection strings can be found at http://www.connectionstrings.com/

提交回复
热议问题