sara.pnu
سه شنبه 17 آبان 1390, 23:56 عصر
با سلام خدمت دوستان عزیزم
من پروژه طراحی سایت دارم با sql که با c# تحت asp.net هستش
وقتی صفحه ایی که قراره یوزرها ثبت نام بشن رو در ویژوال استودیو run میکنم از خط زیر ایراد میگیره!
adapternews.Fill(dstnews,"Tnews");
و میگه:
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)
خواهش میکنم کمکم کنین...
سورس صفحه هم اینه:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class main : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection connews = new SqlConnection("Data Source=(local);Initial Catalog=mobile;Integrated Security=true");
SqlDataAdapter adapternews = new SqlDataAdapter("SELECT * FROM [Tnews] ORDER BY [tarekhroz] DESC ", connews);
DataSet dstnews = new DataSet();
adapternews.Fill(dstnews,"Tnews");
int k = dstnews.Tables["Tnews"].Rows.Count;
for (int i = 0; i < k; i++)
{
TableRow rowpic = new TableRow();
TableCell cellpic = new TableCell();
ImageButton pic = new ImageButton();
TableRow rowtitle = new TableRow();
TableCell celltitl = new TableCell();
Label lbltitle = new Label();
Label lbltext = new Label();
TableRow rowtext = new TableRow();
TableCell celltext = new TableCell();
pic.Width = 100;
pic.Height = 70;
lbltext.Height = 70;
lbltitle.ForeColor = System.Drawing.Color.YellowGreen;
lbltitle.Text = dstnews.Tables["Tnews"].Rows[i][0].ToString();
pic.ImageUrl = dstnews.Tables["Tnews"].Rows[i][3].ToString();
lbltext.Text = dstnews.Tables["Tnews"].Rows[i][2].ToString();
cellpic.Controls.Add(pic);
rowpic.Cells.Add(cellpic);
celltitl.Controls.Add(lbltitle);
rowtitle.Cells.Add(celltitl);
celltext.Controls.Add(lbltext);
rowtext.Cells.Add(celltext);
Table1.Rows.Add(rowpic);
tblnews.Rows.Add(rowtitle);
tblnews.Rows.Add(rowtext);
}
}
من پروژه طراحی سایت دارم با sql که با c# تحت asp.net هستش
وقتی صفحه ایی که قراره یوزرها ثبت نام بشن رو در ویژوال استودیو run میکنم از خط زیر ایراد میگیره!
adapternews.Fill(dstnews,"Tnews");
و میگه:
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)
خواهش میکنم کمکم کنین...
سورس صفحه هم اینه:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class main : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection connews = new SqlConnection("Data Source=(local);Initial Catalog=mobile;Integrated Security=true");
SqlDataAdapter adapternews = new SqlDataAdapter("SELECT * FROM [Tnews] ORDER BY [tarekhroz] DESC ", connews);
DataSet dstnews = new DataSet();
adapternews.Fill(dstnews,"Tnews");
int k = dstnews.Tables["Tnews"].Rows.Count;
for (int i = 0; i < k; i++)
{
TableRow rowpic = new TableRow();
TableCell cellpic = new TableCell();
ImageButton pic = new ImageButton();
TableRow rowtitle = new TableRow();
TableCell celltitl = new TableCell();
Label lbltitle = new Label();
Label lbltext = new Label();
TableRow rowtext = new TableRow();
TableCell celltext = new TableCell();
pic.Width = 100;
pic.Height = 70;
lbltext.Height = 70;
lbltitle.ForeColor = System.Drawing.Color.YellowGreen;
lbltitle.Text = dstnews.Tables["Tnews"].Rows[i][0].ToString();
pic.ImageUrl = dstnews.Tables["Tnews"].Rows[i][3].ToString();
lbltext.Text = dstnews.Tables["Tnews"].Rows[i][2].ToString();
cellpic.Controls.Add(pic);
rowpic.Cells.Add(cellpic);
celltitl.Controls.Add(lbltitle);
rowtitle.Cells.Add(celltitl);
celltext.Controls.Add(lbltext);
rowtext.Cells.Add(celltext);
Table1.Rows.Add(rowpic);
tblnews.Rows.Add(rowtitle);
tblnews.Rows.Add(rowtext);
}
}