Sql连接字符串到我的mdf数据库文件

时间:2018-04-11 16:43:54

标签: c# sql-server database-connection

我的application.exe与我的string dbPath = Application.StartupPath + "\\DATABASE1.MDF"; string strConnection = @"Data Source =.\SQLEXPRESS; AttachDbFilename = [" + dbPath + "]; Integrated Security = True; Connect Timeout = 30; User Instance = True"; 位于同一个文件夹中。我搜索了其他问题并找到了这种方式但是在我启动程序后出现错误

Screenshot

*/48 */4 ***

1 个答案:

答案 0 :(得分:0)

NVM找到了解决方案。问题是[]

string dbPath = Application.StartupPath + "\\DATABASE1.MDF";
        string strConnection =
            @"Data Source =.\SQLEXPRESS; AttachDbFilename = " + dbPath + "; Integrated Security = True; Connect Timeout = 30; User Instance = True";