源码:- 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=.\SQLEXPRESS;AttachDBFilename=|DataDiretory|\Database1.mdf;
- Integrated Security=Ture;User Instance=Ture");
- conn.Open();
- Console.WriteLine("数据库连接成功");
复制代码 错误提示:
|