视频中 测试数据库连接是如下代码:- static void Main(string[] args)
- {
- 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=.\SQLSERVER_WCS;AttachDbFilename="+dataDir+@"\Database1.mdf;Integrated Security=True;User Instance=True");
- SqlConnection conn = new SqlConnection(@"Data Source=.\SQLSERVER_WCS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True");
- conn.Open();
- Console.WriteLine("打开数据库成功");
- Console.ReadKey();
- }
复制代码 请问其中AttachDbFilename=|DataDirectory|\Database1.mdf 中|DataDirectory| 为什么要这么用,(虽然我知道这个表示的是database.mdf所在的文件目录)
|