fsima
چهارشنبه 03 بهمن 1386, 01:39 صبح
به cn.open(); ایراد میگیره همه چی درست دیتابیس ام کانکت
کد ام اینه
protected void Button1_Click(object sender, EventArgs e)
{
string sqlstr = "insert into tbl(Name,Family) values ('" + TextBox1.Text + "','" + TextBox2.Text + "')";
ConnectionStringSettings Settings;
Settings = System.Configuration.ConfigurationManager.Connecti onStrings["connStr"];
string connectionString = Settings.ConnectionString;
SqlConnection cn = new SqlConnection(connectionString);
cn.Open();
using(SqlCommand cmd = new SqlCommand(sqlstr, cn))
cmd.ExecuteNonQuery();
cn.Close();
}
و توی web.confing هم کد زیر رو نوشته ام
<configuration>
<appSettings/>
<connectionStrings>
<add name="connStr" connectionString="Data Source=hamidiya-02f2ed;Initial Catalog=Camera;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
خطا ی زیر رو میده
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
کد ام اینه
protected void Button1_Click(object sender, EventArgs e)
{
string sqlstr = "insert into tbl(Name,Family) values ('" + TextBox1.Text + "','" + TextBox2.Text + "')";
ConnectionStringSettings Settings;
Settings = System.Configuration.ConfigurationManager.Connecti onStrings["connStr"];
string connectionString = Settings.ConnectionString;
SqlConnection cn = new SqlConnection(connectionString);
cn.Open();
using(SqlCommand cmd = new SqlCommand(sqlstr, cn))
cmd.ExecuteNonQuery();
cn.Close();
}
و توی web.confing هم کد زیر رو نوشته ام
<configuration>
<appSettings/>
<connectionStrings>
<add name="connStr" connectionString="Data Source=hamidiya-02f2ed;Initial Catalog=Camera;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
خطا ی زیر رو میده
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)