zoukankan      html  css  js  c++  java
  • 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;
    
    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();
            }
        }
    }
    

    连接结果:




    版权声明:本文博客原创文章。博客,未经同意,不得转载。

  • 相关阅读:
    Python函数高级
    Python 2和3的区别
    GIL,python全局解释器锁
    Python中的 list
    python中的单例
    新式类和经典类
    整理的排序算法
    Python的双下划方法
    Python 中闭包函数和装饰器
    面向对象,特性之继承
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/4756890.html
Copyright © 2011-2022 走看看