انجمن‌هاي فارس وب

نسخه کامل: برقرار نشدن اتصال
شما در حال بازدید از بایگانی ارسال های انجمن هستید این نسخه کامل نیست : برای مشاهده نسخه کامل اینجا کلیک کنید
سلام
وقتی برناممو اجرا می کنم ،اتصال با data base برقرار نمیکند وخطای زیر را می دهد:

نقل قول:
The ConnectionString property has not been initialized.


<configuration>
  <appSettings >
    <add key="mycn" value="Data Source=.\\SQLEXPRESS; Initial Catalog=DB_SANAT; Integrated Security=true ;Persist Security Info=False" />
  </appSettings>
</configuration>

و در #C هم کد زیر را نوشتم:

public DALPERSON() //سازنده
        {
            cn = new SqlConnection(ConfigurationSettings.AppSettings["mycn"]);
           // cn = new SqlConnection("Integrated Security=true ;Persist Security Info=False;Initial Catalog=DB_SANAT;Data Source=.\\SQLEXPRESS");
        }

        public void ADDPERSON(string f, string l, int a)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = cn;
            cmd.CommandText = "INSERT INTO person (firstname,lastname,age) VALUES (N'" + f + "',N'" + l + "'," + a.ToString() + ")";
            try
            {
                cn.Open();
                cmd.ExecuteNonQuery();
                cn.Close();


موقعی که از App.config استفاده نمی کنم و مستقیما در sql connection رشته ی اتصال را می دهم ، مشکلی ندارد و اجرا می شود ولی وقتی از App.configاستفاده می کنم ،خطا می دهد.چرا؟

مرجع آدرس ها