Results 1 to 6 of 6

Thread: could not open a connection to sql server

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Thumbs up could not open a connection to sql server

    I am using sql server 2005 and asp.net 2.0 in my home.

    I established connection in my application and put code in page load

    protected void Page_Load(object sender, EventArgs e)
    {
    string constring = "server=.\\SQLEXPRESS;uid=sa;pwd=;data source=dbAshok";

    //Open the connection
    sqlconnection = new SqlConnection(constring);

    sqlconnection.Open();

    string strquery = "select *from Employee";

    dataset = new DataSet(strquery);

    sqlconnection.Close();
    }

    But i got an error in open the connection. My error is below.
    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 couldn't fix this bugs. Please suggest me.

    Hope yours reply.

    Thanks
    Failing to plan is Planning to fail

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: could not open a connection to sql server

    Hey,

    So the first thing that I would suggest is that you put your connection string into the web.config file of your application. This will make things much easier going forward, as you will be able to modify it without having to re-compile your application.

    Once you have done that, verify that you have got the correct connection string by looking here:

    http://www.connectionstrings.com/sql-server-2005

    Do you have SQL Server Management Studio? If so, can you connect through that to your database using the same credentials as you are trying here?

    Gary

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: could not open a connection to sql server

    first, it's not a good idea to use the SA/no password for the login.... might want to change that ASAP.

    Secondly, is the connection string correct? You are attempting to connect to the SQLExpress instance of the local server. Is SQL Express installed, or a full SQL Server? And is it on the same server as the web server?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: could not open a connection to sql server


  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Thumbs up Re: could not open a connection to sql server

    Dear guys,

    Thanks for your reply. I got it as what you told.

    Thanks again.
    Failing to plan is Planning to fail

  6. #6
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: could not open a connection to sql server

    Hey,

    So that other people can benefit from your experience, can you explain exactly what you had to change to make it work?

    Also, can you remember to go back and mark your thread as resolved?

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width