SQL 数据库无法连接
stringdataDri=AppDomain.CurrentDomain.BaseDirectory;if(dataDri.EndsWith(@"\bin\Debug\...
string dataDri = AppDomain.CurrentDomain.BaseDirectory;
if (dataDri.EndsWith(@"\bin\Debug\")
|| dataDri.EndsWith(@"\bin\Release\"))
{
dataDri = System.IO.Directory.GetParent(dataDri).Parent.Parent.FullName;
AppDomain.CurrentDomain.SetData("DataDriectory", dataDri);
}
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS:AttachDBFilename=|DataDriectory|\Database1.mdf;
Integrated Security=true;User Instance=true");
conn.Open();
Console.WriteLine("打开数据库成功");
Console.ReadKey();
系统提示的内容是:provider: SQL 网络接口, error: 25 - 连接字符串无效 展开
if (dataDri.EndsWith(@"\bin\Debug\")
|| dataDri.EndsWith(@"\bin\Release\"))
{
dataDri = System.IO.Directory.GetParent(dataDri).Parent.Parent.FullName;
AppDomain.CurrentDomain.SetData("DataDriectory", dataDri);
}
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS:AttachDBFilename=|DataDriectory|\Database1.mdf;
Integrated Security=true;User Instance=true");
conn.Open();
Console.WriteLine("打开数据库成功");
Console.ReadKey();
系统提示的内容是:provider: SQL 网络接口, error: 25 - 连接字符串无效 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询