日期:2014-05-17 浏览次数:20890 次
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("DateDirectory", dataDir); } using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS; AttachDBFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True")) { conn.Open(); Console.WriteLine("打开数据库成功"); Console.ReadKey(); }