zoukankan      html  css  js  c++  java
  • ADO.NET(一)数据库连接串的几种写法

        class Program
        {
            static void Main(string[] args)
            {
                SqlConnection conn = new SqlConnection();
    
                //1.手写
                //string connStr = "server=.;database=db1;uid=sa;pwd=123";
    
                //2.SqlConnectionStringBuilder生成连接字符串
                //SqlConnectionStringBuilder connStrBuilder = new SqlConnectionStringBuilder();
                //connStrBuilder.DataSource = ".";//设置数据源
                //connStrBuilder.InitialCatalog = "db1";//数据库名
                //connStrBuilder.UserID = "sa";//账号
                //connStrBuilder.Password = "123";//密码
                //connStrBuilder.Pooling = false;//禁用连接池
                //string connStr = connStrBuilder.ConnectionString;
    
                //3.读取配置文件里的连接字符串
                //3.1
                //string connStr = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;//读取连接字符串
                //3.2
                string connStr = ConfigurationManager.AppSettings["connStr"].ToString();
    
    
                //连接字符串如果任何一个元素设置不正确,都不能正常打开conn
                conn.ConnectionString = connStr;
                conn.Open();
                conn.Close();
            }
        }
  • 相关阅读:
    不舍
    java 笔记
    Javascript 行为委托
    JavaScript 函数调用的 this词法
    Javascript 闭包
    Javascript 原型链
    理解css的BFC
    多模态检索之CCA算法
    MySQL 基础概念、基础配置、密码破解
    Python的进程和线程
  • 原文地址:https://www.cnblogs.com/wxhao/p/13629573.html
Copyright © 2011-2022 走看看