时间:2021-07-01 10:21:17 帮助过:3人阅读
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SQLTest
{
class Program
{
static void Main(string[] args)
{
//连接数据库
string connection =
"server=潘尚\\SQLEXPRESS;database=db_test;Trusted_Connection=true";
SqlConnection sc = new SqlConnection();
sc.ConnectionString = connection;
try
{
sc.Open();
Console.WriteLine("已经打开数据库连接!");
}
catch (Exception ex)
{
Console.WriteLine("打开数据库错误:{0}", ex.Message);
}
finally
{
sc.Close();
Console.WriteLine("数据库连接已关闭!");
}
System.Console.ReadLine();
}
}
}
版权声明:本文博客原创文章。博客,未经同意,不得转载。
ADO.net之2-成功连接到数据库---ShinePans
标签: