public static SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString); public static DataTable Filladptor(SqlCommand cmd) { DataTable dt = new DataTable(); cmd.Connection = cn; SqlDataAdapter adp = new SqlDataAdapter(cmd); try { //cmd = new SqlCommand(); if (cn.State == ConnectionState.Closed) { cn.Open(); } adp.Fill(dt); } catch (Exception ex) { errmsg = ex.Message; } finally { cmd.Dispose(); if (cn.State == ConnectionState.Open) { cn.Close(); } } return dt; }
<add name="constr" connectionString="Data Source=MyServerIp;User ID=myusername;Password=mypassword;persist security info=False;Initial catalog=myDB;Connection Timeout=15;Connection Lifetime=0;Min Pool Size=0;Max Pool Size=100;Pooling=true;" providerName="System.Data.SqlClient"/>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)