C# Web Site. Connecting to SQL Server. Test Connection Fine...BUT

Discussion in 'ASP .Net' started by samadams_2006@yahoo.ca, Aug 31, 2007.

  1. Guest

    Hello,

    I have a problem that I'm hoping someone will be able to help me
    resolve.

    1) I have a C# Web Site in which I connect to the database: "Install
    Microsoft SQL Server 2005 Express Edition" via the link on:

    http://msdn2.microsoft.com/en-us/express/bb410792.aspx

    This Web Site has various versions, but I use the following version:

    -----------------------------------------------------------------------------------------------------------------------------------------------------
    Install Microsoft SQL Server 2005 Express Edition
    Microsoft SQL Server 2005 Express Edition is the free, easy-to-use,
    lightweight version of SQL Server 2005. Integrated with Microsoft
    Visual Studio 2005, SQL Server Express makes it easy to develop data-
    driven applications that are rich in capability, offer enhanced
    storage security, and are fast to deploy. SQL Server Express is free
    to redistribute and can be seamlessly upgraded to more sophisticated
    versions of SQL Server.

    Download * (36.5 MB)
    -----------------------------------------------------------------------------------------------------------------------------------------------------

    2) I connect to this SQL Server version via the "Server Explorer" Tab
    inside Visual Studio 2005.

    Here's the connection string I am using:

    Data Source=.\SQLEXPRESS;AttachDbFilename=E:\MyDB.mdf;User ID=sa

    3) When I click on the "Test Connection" command button, it states:

    "Test Connection Succeeded".

    4) In spite of all this, when I run the application, I get an error
    on the "End Try" of a "Try Catch" in my code. This error states:

    "SQL Exception was unhandled by user code. 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".

    5) Question: Does anyone have any idea how to resolve this error.
    The "Test Connection" said that it was fine, but it appears not to
    be. If it is indeed a problem with "under the default settings SQL
    Server does not allow remote connections", I've looked, but how do you
    change these settings?

    Any ideas on how to proceed would be helpful.

    Thanks
    Sam
     
    , Aug 31, 2007
    #1
    1. Advertising

  2. sloan Guest

    The website may not be able to see E:\mydb.mdf. (or rather the use account
    the website uses)

    Most people put the mdf in a relative path from the website root.


    //
    "SQL Exception was unhandled by user code. 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".//

    This error is kinda like "Your car is making a noise, it may be the engine
    not running well".

    The remote connections part that is. If you're on the same box, then you
    aren't doing remote calls.

    The error is basically saying "You cannot connect to the database".

    ............

    In 2.0 asp.net there is a special folder called "App_Data". Most people put
    their database in there.

    OR you can provide rights to the e:\yourdb.mdf to the account which asp.net
    uses.

    I'm pretty sure this is the issue.








    <> wrote in message
    news:...
    > Hello,
    >
    > I have a problem that I'm hoping someone will be able to help me
    > resolve.
    >
    > 1) I have a C# Web Site in which I connect to the database: "Install
    > Microsoft SQL Server 2005 Express Edition" via the link on:
    >
    > http://msdn2.microsoft.com/en-us/express/bb410792.aspx
    >
    > This Web Site has various versions, but I use the following version:
    >
    > -----------------------------------------------------------------------------------------------------------------------------------------------------
    > Install Microsoft SQL Server 2005 Express Edition
    > Microsoft SQL Server 2005 Express Edition is the free, easy-to-use,
    > lightweight version of SQL Server 2005. Integrated with Microsoft
    > Visual Studio 2005, SQL Server Express makes it easy to develop data-
    > driven applications that are rich in capability, offer enhanced
    > storage security, and are fast to deploy. SQL Server Express is free
    > to redistribute and can be seamlessly upgraded to more sophisticated
    > versions of SQL Server.
    >
    > Download * (36.5 MB)
    > -----------------------------------------------------------------------------------------------------------------------------------------------------
    >
    > 2) I connect to this SQL Server version via the "Server Explorer" Tab
    > inside Visual Studio 2005.
    >
    > Here's the connection string I am using:
    >
    > Data Source=.\SQLEXPRESS;AttachDbFilename=E:\MyDB.mdf;User ID=sa
    >
    > 3) When I click on the "Test Connection" command button, it states:
    >
    > "Test Connection Succeeded".
    >
    > 4) In spite of all this, when I run the application, I get an error
    > on the "End Try" of a "Try Catch" in my code. This error states:
    >
    > "SQL Exception was unhandled by user code. 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".
    >
    > 5) Question: Does anyone have any idea how to resolve this error.
    > The "Test Connection" said that it was fine, but it appears not to
    > be. If it is indeed a problem with "under the default settings SQL
    > Server does not allow remote connections", I've looked, but how do you
    > change these settings?
    >
    > Any ideas on how to proceed would be helpful.
    >
    > Thanks
    > Sam
    >
     
    sloan, Aug 31, 2007
    #2
    1. Advertising

  3. Re: C# Web Site. Connecting to SQL Server. Test Connection Fine...BUT

    On Aug 31, 11:10 pm, wrote:
    > "SQL Exception was unhandled by user code. 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".
    >


    http://support.microsoft.com/default.aspx?scid=kb;EN-US;914277
     
    Alexey Smirnov, Aug 31, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Adam P
    Replies:
    0
    Views:
    492
    Adam P
    Sep 27, 2005
  2. Mufasa
    Replies:
    0
    Views:
    830
    Mufasa
    Jun 10, 2007
  3. J. Muenchbourg
    Replies:
    0
    Views:
    125
    J. Muenchbourg
    Aug 6, 2003
  4. guy
    Replies:
    2
    Views:
    449
    Aaron Bertrand [MVP]
    Feb 23, 2004
  5. JJA
    Replies:
    3
    Views:
    125
Loading...

Share This Page