Where do I need the connectionSting property?

0

I have a question, what is this message about and how do I resolve it? "ConnectionString property has not been initialized".

In my code there is a variable that stores a string for my connection, and I want to use it but it has marked me this message. I'm not sure where I'm wrong in the code, I hope and can help me please!

Here I just agree as I create the connection variable.

      public partial class AuthorBrowser : System.Web.UI.Page
 {

private string connectionString = WebConfigurationManager.ConnectionStrings["PUBG"].ConnectionString;


protected void Page_Load(object sender, EventArgs e) ...

private void Metodo() ...

protected void crearconexion(object sender, EventArgs e)
{

   ///Imagina que hay código como si fuera matrix
  ///
  ///
  //

        string conexion = "Data Source ="+Servidor+"; Initial Catalog ="+BD+"; Integrated Security = SSPI";

        Session["conexion"] = conexion;

 }

Here I want to make use of that connection, but it marks me the error!

   protected void Gridview1_SelectedIndexChanged(object sender, EventArgs e)
{


    {
        SqlConnection sql = new SqlConnection((string)Session["conexion"]);
        {

            sqlCon.Open();
            string SQLTable;
            SQLTable = "SELECT  * FROM empleados ";


            SqlDataAdapter sqlDa = new SqlDataAdapter(SQLTable, sqlCon);
            DataTable dtbl = new DataTable();
            sqlDa.Fill(dtbl);
            GridView1.DataSource = dtbl;
            GridView1.DataBind();
            sqlCon.Close();
        }
    }

}
}
    
asked by Alias Wright 29.07.2018 в 05:21
source

0 answers