c#ado.net连接数据库失败,什么原因呢?下面是我在C#控制台程序中的语句,哪里出错了? 5
stringdataDir=AppDomain.CurrentDomain.BaseDirectory;if(dataDir.EndsWith(@"\bin\Debug\...
string dataDir = AppDomain.CurrentDomain.BaseDirectory;
if (dataDir.EndsWith(@"\bin\Debug\")
|| dataDir.EndsWith(@"\bin\Release\"))
{
dataDir = System.IO.Directory.GetParent(dataDir).Parent.Parent.FullName;
AppDomain.CurrentDomain.SetData("DataDirectory", dataDir);
}
SqlConnection conn = new SqlConnection(@"Data Source=伟超\MSSQLSERVER:AttachDBFilename=|
DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True");
conn.Open();
Console.WriteLine("打开数据库连接成功");
Console.ReadKey();
这是出错的提示 展开
if (dataDir.EndsWith(@"\bin\Debug\")
|| dataDir.EndsWith(@"\bin\Release\"))
{
dataDir = System.IO.Directory.GetParent(dataDir).Parent.Parent.FullName;
AppDomain.CurrentDomain.SetData("DataDirectory", dataDir);
}
SqlConnection conn = new SqlConnection(@"Data Source=伟超\MSSQLSERVER:AttachDBFilename=|
DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True");
conn.Open();
Console.WriteLine("打开数据库连接成功");
Console.ReadKey();
这是出错的提示 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询