Results 1 to 3 of 3

Thread: Ms Sql Server 2005 Error

  1. #1
    Join Date
    Jun 2011
    Posts
    2

    sad Ms Sql Server 2005 Error

    HI,m getting the following error wen running my asp.net web page :-

    A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

    i have checked my server, its running properly,my Named pipes is enabled but still m not able 2 figure out wer m i going wrong

    the following iz my code for the page,wer i want the data in the DB 2 b displayed in my GridView :

    using System.Data.SqlClient;

    public partial class products : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    string Sel = "Select * from ItemTable";
    SqlConnection Con = new SqlConnection();
    Con.ConnectionString = "Server=deepti;Database=Database.mdf;Integrated Security=SSPI;";
    SqlCommand cmd = new SqlCommand(Sel, Con);
    Con.Open();
    DataTable dt = new DataTable();
    dt.Columns.Add(new DataColumn("product_id", typeof(int)));
    dt.Columns.Add(new DataColumn("product_name", typeof(string)));
    dt.Columns.Add(new DataColumn("unit_price", typeof(float)));

    SqlDataReader reader = cmd.ExecuteReader();
    while (reader.Read())
    {
    DataRow dr = dt.NewRow();
    dr["product_id"] = Convert.ToInt32(reader["product_id"]);
    dr["product_name"] = reader["product_name"];
    dr["unit_price"] = Convert.ToDecimal(reader["unit_price"]);
    dt.Rows.Add(dr);
    }
    Con.Close();
    GridView1.DataSource = dt;
    GridView1.DataBind();
    }
    }

    it is showing the error at Con.Open();

    m using VS 2008 and MS SQL SERVER 2005 as backend.......pls help me bcaz m trying 2 solve da problem since 2 weeks...............pls help

  2. #2
    Join Date
    Jan 2006
    Posts
    605

    Re: Ms Sql Server 2005 Error

    Can you try to surround your code with a try/catch

    For an example, see this link :
    http://msdn.microsoft.com/en-us/libr...on.number.aspx

    I add always the properties Source,TargetSite , StackTrace,ErrorCode and Number the string so obtained is really helpful to detect the source of the problem

    With the following link, you may find a solution to your problem
    http://blogs.msdn.com/sql_protocols/...28/474698.aspx

  3. #3
    Join Date
    Jun 2011
    Posts
    2

    Re: Ms Sql Server 2005 Error

    THANK U so much Janos for ur response.................but the second link dat u mentioned just describes da meaning of the error but not the solution to my problem........................hope if u cud help me wid more better solution........plz help.

Similar Threads

  1. Replies: 3
    Last Post: 02-04-2011, 07:33 AM
  2. Replies: 5
    Last Post: 13-02-2009, 09:57 AM
  3. Replies: 7
    Last Post: 26-09-2008, 05:36 PM
  4. Upgrade fails: SQL Server Express 2005 to SQL Server 2005
    By Steve BB in forum Small Business Server
    Replies: 3
    Last Post: 11-06-2008, 07:37 PM
  5. Replies: 8
    Last Post: 12-04-2007, 11:15 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,288,163.01245 seconds with 17 queries