连接字符串中的窗体格式无法在Dbconnection页面上获取 [英] window form in connection string could not get on Dbconnection page

查看:80
本文介绍了连接字符串中的窗体格式无法在Dbconnection页面上获取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生我正在使用app配置文件创建连接并在Dbconnection.class页面上访问此连接,但我在ConfigurationManager中遇到错误请解决它

并告诉我这是什么问题代码。



sir i am using app config file for creating connection and access this connection on Dbconnection.class page but i get error in ConfigurationManager in this pls solve it
and tell me what is the problem in this code.

using System.Data.SqlClient;
using System.Configuration;


namespace hello42_win
{
       
   public class Dbconnection : Form
    {
        SqlConnection sqlConn;


        public SqlConnection OpenConnection()
        {
                       sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConString"].ConnectionString);

            if (sqlConn.State != ConnectionState.Open)
            {
                sqlConn.Open();
            }
            return sqlConn;
        }
        public SqlConnection CloseConnection()
        {
            if (sqlConn.State != ConnectionState.Closed)
            {
                sqlConn.Close();
            }
            return sqlConn;
        }

    }
}

推荐答案

试试这个链接



http://www.connectionstrings.com/store-connection-string-in-webconfig
try this link

http://www.connectionstrings.com/store-connection-string-in-webconfig


这篇关于连接字符串中的窗体格式无法在Dbconnection页面上获取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆