本帖最后由 Sword 于 2013-5-18 01:25 编辑
static void Main(string[] args)
{
string dateDir = AppDomain.CurrentDomain.BaseDirectory;
if(dateDir.EndsWith(@"\bin\Debug\")||dateDir.EndsWith(@"\bin\Release"))
{
dateDir=System.IO.Directory.GetParent(dateDir).Parent.FullName;
AppDomain.CurrentDomain.SetData("DataDirectory",dateDir);
}
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDBFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True");
conn.Open();
Console.WriteLine("打开数据库连接成功 ");
Console.ReadKey();
} |