Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C#
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;
        }

    }
}
Posted
Updated 24-Sep-14 21:23pm
v2
Comments
Fredrik Bornander 25-Sep-14 3:24am    
What error are you getting?
Harshad Kathiriya 25-Sep-14 3:47am    
how to set connection string in config file?

1 solution

try this link

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900