using System.Data; using System.Data.SqlClient; class Pranson() { public static void Main() { //创建数据库链接对象 string connString = "Server=.;DataBase=CourseManageDB;Uid=sa;Pwd=123456"; SqlConnection conn = new SqlConnection(connString); //打开链接 conn.Open(); if (conn.State == ConnectionState.Open) Console.WriteLine("数据库链接成功"); //断开链接 conn.Close(); if (conn.State == ConnectionState.Closed) Console.WriteLine("数据库断开链接"); Console.ReadKey(); } }
标签:Console,数据库,System,server,State,sql,net,链接,conn From: https://www.cnblogs.com/tlfe/p/18152727