0

I'm using the entity framework in a winforms application.

When i set scsb.DataSource ="localhost" every thing works fine but when i try to connect to onother DB server i got an exception:

"The underlying provider failed on Open."

public DistributionSSEntities1 Connection()
{
    var scsb = new SqlConnectionStringBuilder();
    scsb.DataSource = "192.168.1.100";
    scsb.InitialCatalog = "DistributionSS";
    scsb.IntegratedSecurity = true;
    //------------------------
    EntityConnectionStringBuilder builder = new EntityConnectionStringBuilder();
    builder.Metadata ="res://*/Model.Model.csdl|res://*/Model.Model.ssdl|res://*/Model.Model.msl";
    builder.Provider = "System.Data.SqlClient";
    builder.ProviderConnectionString = scsb.ConnectionString;
    DistributionSSEntities1 db = new DistributionSSEntities1(builder.ToString());
    return db;
}
8
  • Check this link Commented Jun 5, 2013 at 10:08
  • Do that server works? try to access it first using your vs studio. check also your web config connection string. Commented Jun 5, 2013 at 10:09
  • are you sure you have windows authentication account for the server you are trying to access Commented Jun 5, 2013 at 10:16
  • 2
    The "The underlying provider failed on Open" exception has an InnerException which tells you exactly what is wrong. Either TCP/IP access is not enabled, the server is not running or not accessible (firewall?), or the user you try to access the database with is not authorized to do so. Commented Jun 5, 2013 at 10:17
  • @CodeCaster: if the sql server rejected the connection/login attempt you're almost certainly NOT going to get valid info from an inner exception - see my edit on why. Commented Jun 5, 2013 at 15:36

2 Answers 2

2

Has the remote Sql been setup to allow remote connections? Has the remote Sql been allowed access through the windows firewall... there's so many reasons why it wouldn't connect.

You're using Integrated Security - which may work great for a local Sql; but the network user that your WinForm app is running under must have the correct rights to access the remote box.

I'd suggest to start eliminating possibilities do the following:

  1. Check the Sql logs on the target server. That always has the exact reason why an attemp failed - not the watered down version you get through the exception. (eg. C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\Log)

  2. Connect to it using a sql username password - not integrated security to make sure it's not that

  3. Firewall

EDIT

It's important to remember that the error messages return to the client regarding login attempt failures are purposefully obscure or without information - to limit an attacker gaining enough information to improve the attack (see the technet article for proof). So checking the Sql Server logs is a necessity - if your login/connection attempt actually made it to the server.

From Article:

To increase security, the error message that is returned to the client deliberately hides the nature of the authentication error. However, in the SQL Server error log, a corresponding error contains an error state that maps to an authentication failure condition. Compare the error state to the following list to determine the reason for the login failure.

Sign up to request clarification or add additional context in comments.

Comments

0
 public DistributionSSEntities Connection()
    {
        string ConString = "SERVER=192.168.1.100;DATABASE=DistributionSS;UID=sa;PASSWORD=125;";
        SqlConnectionStringBuilder SCB= new SqlConnectionStringBuilder(ConString);
        //------------------------
        EntityConnectionStringBuilder builder = new EntityConnectionStringBuilder();
        builder.Metadata = "res://*/Model.Model.csdl|res://*/Model.Model.ssdl|res://*/Model.Model.msl";
        builder.Provider = "System.Data.SqlClient";
        builder.ProviderConnectionString = SCB.ConnectionString;
        DistributionSSEntities db = new DistributionSSEntities(builder.ToString());
        return db;
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.