zoukankan      html  css  js  c++  java
  • asp .net连接打开数据库初步

    1 //测试连接字符串是否成功
    2  #region
    3 using System;
    4
    using System.Collections.Generic;
    5
    using System.Linq;
    6
    using System.Web;
    7
    using System.Web.UI;
    8
    using System.Web.UI.WebControls;
    9
    using System.Data.SqlClient;
    10
    using System.Configuration;
    11

    12 public partial class test_Default : System.Web.UI.Page
    13
    {
    14
        protected void Page_Load(object sender, EventArgs e)
    15
        {
    16
            string str = ConfigurationManager.ConnectionStrings["haqiuConnectionString"].ConnectionString;
    17
            SqlConnection strConn = new SqlConnection(str);
    18
            if (strConn == null)
    19
            {
    20
                Response.Write("连接字符串为空!");
    21
            }
    22
            else
    23         {
    24
                Response.Write("连接字符串不为空!");
    25
            }
    26
        }
    27
    }
    28
    #endregion
    29
    30 //打开数据库连接
    31 #region
    32 using System;
    33
    using System.Collections.Generic;
    34
    using System.Linq;
    35
    using System.Web;
    36
    using System.Web.UI;
    37
    using System.Web.UI.WebControls;
    38
    using System.Data.SqlClient;
    39
    using System.Configuration;
    40

    41 public partial class test_Default : System.Web.UI.Page
    42
    {
    43
        protected void Page_Load(object sender, EventArgs e)
    44
        {
    45
            string str = ConfigurationManager.ConnectionStrings["haqiuConnectionString"].ConnectionString;
    46
            SqlConnection strConn = new SqlConnection(str);
    47
            if (strConn.State.ToString()=="Closed")
    48
            {
    49
                strConn.Open();
    50
                Response.Write("数据库连接已经打开!");
    51
            }
    52
            else
    53         {
    54
                Response.Write("数据库连接无法打开!");
    55
            }
    56
        }
    57
    }
    58
    #endregion
    59

    WebDriver
  • 相关阅读:
    IEnumerable<T>接口主要成员
    SQL LinqToSql Lambda QA
    css网页布局兼容性有哪些要点与诀窍
    【转】解决大量图片造成的页面延迟
    C# override,new 的区别+C# 接口的显示实现和隐示实现
    ap_invoice_distributions_all到xla_ae_lines
    Mysql从索引原理对SQL分析优化实战
    如何实现IM表情、图片、文件之间的通讯?
    五步教你如何使用k8s快速部署ES
    ClickHouse MergeTree引擎的简单介绍
  • 原文地址:https://www.cnblogs.com/wwwzzg168/p/4121536.html
Copyright © 2011-2022 走看看