class Program
{
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 comn = new SqlConnection(@"Data Source=.\;AttachDBFilename=|DataDirectory|\Database1.mdf;Integrated Security=true; User Instance=true" );
comn.Open();
Console.WriteLine("打开数据库成功!");
Console.ReadKey();
}
} |