您好,欢迎来到爱玩科技网。
搜索
您的当前位置:首页ADO.net之2-连接数据库成功---ShinePans

ADO.net之2-连接数据库成功---ShinePans

来源:爱玩科技网


数据库的配置: 连接字符串:server=潘尚\\SQLEXPRESS;database=db_test;Trusted_Connection=true 连接代码: using System;using System.Collections.Generic;using System.Data.SqlClient;using System.Linq;using System.Text;using System.Threading.Tasks;

数据库的配置:



连接字符串: server=潘尚\\SQLEXPRESS;database=db_test;Trusted_Connection=true


连接代码:
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();
 }
 }
}

连接结果:



Copyright © 2019- aiwanbo.com 版权所有 赣ICP备2024042808号-3

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务