文件名称:数据库连接操作
文件大小:1KB
文件格式:TXT
更新时间:2016-06-24 05:46:51
打开数据库
打开数据库连接 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); } using( SqlConnection comn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDBFilename=|DataDirectory|\Database2.mdf;Integrated Security=True;User Instance=True")); comn.Open(); Console .WriteLine ("打开数据库连接成功"); Console.ReadKey();