SQL Server 2008 Connection

Discussion in 'Databases' started by rohde, May 26, 2009.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. When I try to access my site, I get a server error:

    ======================
    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 used the connection string from the control panel:

    ===============
    "Data Source=tcp:esql2k801.discountasp.net;Initial Catalog=SQL2008_633158_massif;User ID=SQL2008_633158_massif_user;Password=******;"
    =================

    Which means that my web.config contains this (with the proper password instead of the asterisks, of course):

    ================
    <connectionStrings>
    <add name="ApplicationServices" connectionString="Data Source=tcp:esql2k801.discountasp.net;Initial Catalog=SQL2008_633158_massif;User ID=SQL2008_633158_massif_user;Password=********;" providerName="System.Data.SqlClient"/>
    </connectionStrings>
    ====================

    I should mention that I can without any problems connect to the db with SSMS on my local machine, it is only when my ASP.NET MVC app tries to connect that I experience any problems.
     
  2. Not any ideas? This is driving me crazy.
     
  3. Does that mean you are running the app on your local machine as well? To clarify, where is the application running?
     
  4. My ASP.NET MVC app is deployed at discountASP.NET. This is the app that gives me the connection issues.

    But on my local machine, I can access the database with SSMS.

    Now, the problem is that the connection string I use in my web.config is the same as from the control panel (see my original post for the connection string).
     
  5. Bruce

    Bruce DiscountASP.NET Staff

    i suspect your app is using another connection string. Try change your web.config to the following

    <connectionStrings>
    <clear />
    <add name="ApplicationServices" connectionString="Data Source=tcp:esql2k801.discountasp.net;Initial Catalog=SQL2008_633158_massif;User ID=SQL2008_633158_massif_user;Password=********;" providerName="System.Data.SqlClient"/>
    </connectionStrings>

    This will remove all inherited connection string and hopefull will produce an error saying a connection string is missing.
     
  6. I'm having the same problem. Does anyone know why it happens and how to resolve it?
    Thanks.
     
  7. Hi,
    Post what you currently have between your <connectionStrings> entries.
    Comment out anything sensitive, like passwords.
    All the best,
    Mark
     
  8. Hello,

    At the moment I'm trying to do a small connection test like this:

    -------------------------------------------------------------
    string connStr = "Data Source=tcp:esql2k801.discountasp.net;Initial Catalog=SQL2008_63*4***_***;User ID=SQL2008_***_user**_user;Password=*****;";

    SqlConnection conn = new SqlConnection(connStr);
    if(conn.State == System.Data.ConnectionState.Closed)
    conn.Open();
    --------------------------------------------------------------
    I have re-attached the BD but with no success.
    Thanks for the help
     
  9. Hi,
    That is one way you can do it, handy for tests.
    Give a short description of what you want to do and I'll try and post a code sample.
    (Once you go live you should always try and use the web.config for your SQL connection.)
    All the best,
    Mark
     
  10. Hi,
    The problem is that if I cannot connect using this sample code, how can I connect using other techniques? It should work even if I don't have the SQL connection configured in web.config...

    I always got the following error

    'A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible....'

    The connection string is exactly the one provided by the control panel.
    Thanks
     
  11. Hi,
    This can be frustrating, up until the point you get it working.
    What I find easiest when testing against remote data is to first make sure your web.config has a valid connection section.
    Then create a data test page with Visual Studio. (Or Visual Web Developer.)
    If you can't connect DASP has a handy Web tool you can use to test your data.
    https://sqlwebadmin.discountasp.net/

    Use that to log into your DB and test the connection you are using and the SQL from your code.

    I'm going to add this tip to a Webcast for DASP accounts, once I finish the one I'm working on that is. ;-)
    All the best,
    Mark

    PS - Yes your local web.config can point to the remote SQL Server, but your own local security/firewall may interfere.
     
  12. Hello,
    I tried the web tool yesterday and it worked fine. That´s why I don't understand what is happening...
    I had another configuration in another site with sql 2005 and never had any problems but know with sql 2008... :(
    Thanks
     
  13. Hi,
    Here's a very useful trick when something like that happens with your remote servers.
    Notice in my web.config that I'm Clearing, then Removing and finally Adding.
    This at first clears any connections, even if default, which may actually be interfering.
    Then I'm adding both a SQL Server 2005 and 2008 connection...
    While at the same time tossing in an additional trick just in-case anything is looking for an Express SQL conn.
    Everything between the lines below is valid and works, except where I've commented out the actual user settings.

    -----------------------------------
    <connectionStrings>
    <clear />
    <remove name="LocalSqlServer"/>
    <add name="LocalSqlServer" connectionString="Data Source=tcp:sql2k5.discountasp.net;Initial Catalog=SQL2005_msftwise;User ID=SQL2005_msftwise_user;Password=****" providerName="System.Data.SqlClient" />
    <remove name="SQL2005_msftwise_userConnectionString"/>
    <add name="SQL2005_msftwise_userConnectionString" connectionString="Data Source=tcp:sql2k.discountasp.net;Initial Catalog=SQL2005_msftwise;Persist Security Info=True;User ID=SQL2005_msftwise_user;Password=****" providerName="System.Data.SqlClient" />
    <remove name="SQL2008_msftwise_userConnectionString"/>
    <add name="SQL2008_msftwise_userConnectionString" connectionString="Data Source=tcp:sql2k8.discountasp.net;Initial Catalog=SQL2008_wisemx;Persist Security Info=True;User ID=SQL2008_wisemx_user;Password=****" providerName="System.Data.SqlClient" />
    </connectionStrings>
    -----------------------------------
     
  14. Hi Wisemx,
    I tried to use the sample You gave me but the result is the same... unfortunately!
    I've configured de web.config file and then I've used the following code
    --------------------------------------------------
    ConnectionStringSettingsCollection connectionStrings = ConfigurationManager.ConnectionStrings;
    string connStr = connectionStrings["RemoteConn"].ConnectionString;

    using (SqlConnection connection = new SqlConnection(connStr))
    {
    connection.Open();
    }
    --------------------------------------------------
    By the way, i had to put "Data Source=tcp:esql2k8...."

    Thanks anyway.
     
  15. ...Oops...Made a typo in there, yes it is supposed to have "Data Source="
    (I'm wrestling with my 3 kids today as I type these things...they seem to have super powers!)
    All the best,
    Mark
     
  16. It seems like it's not related to your web.config setup at all since you have already tried using a hardcoded connection string and that also failed: http://community.discountasp.net/showpost.php?p=32273&postcount=8

    Where are you running this code test from? Is it:
    • A local test from your development computer to the DASP SQL Server? OR
    • A hosted web application test from a DASP web server to the DASP SQL Server?
    If you're certain the connection string is correct and you're performing a remote development machine -> DASP SQL Server connection attempt, then I agree with Mark; I suspect the connection failure is being caused by your local firewall or security policy issue.

    If you suspect this is a remote development machine problem and you want to try another method to connect to the SQL Server other than your own code you could try using SQL Server Management Studio installed locally. If you don't already have it, the express version is free - http://www.microsoft.com/express/sql/download/

    If this is a hosted web application problem then I'd be just as confused as you but I suspect it's not. The fact that https://sqlwebadmin.discountasp.net/ is connecting to your db without any issues strengthens my suspicion that this is a local firewall problem.
     
  17. Hi Mark and Joe!

    Thank You both for Your Help.

    Definitely is a firewall problem since in my last trial I was doing a local test from my development computer to the DASP SQL Server and I got the error, and know, when I hosted the application it worked fine.

    The curious thing was that I was getting the same error when trying to use Linq To Sql Classes with a WebService in the hosted application and because of that I didn't realize that it could be a firewall problem at the local environment.

    Now, I need to configure the web service and I think it will work fine.
    Hope I can find a good thread;)

    Once more, thank You very much.
     
  18. ..is the right answer! Result, well done.
     
  19. ...Whew! :)
     
  20. well,I have also has the same problem as you.Sometimes,the database has a big difficulty of connnecting to the program.That is a troublesome thing for us.
     
  21. The same

    I am on the same server as you and I cannot connect to it either any one figure it out yet I have a ticket opened on it
     
  22. ...If any of you want me to try connecting PM me with your account info.
    (From SQL Server, VS file or the DASP on-line DB admin tool.)
    note: I do not keep your account info and there is no charge for this.
    All the best,
    Mark
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page