locked
entity framework, why is this connection string wrong? RRS feed

  • Question

  • User1974248332 posted

    Hi guys, Im trying to connect to a remote database using entity framework, the database is there already created so I just need the correct string to connect to it, but I literally tried dozens os different strings and none of them work, can you guys tell me what is wrong? I can connect without problems using SQL server Manager.

    <add name="default_connection" connectionString="metadata=res://*/App_Code.myApp.csdl|res://*/App_Code.myApp.ssdl|res://*/App_Code.myApp.msl;provider=System.Data.SqlClient;
    provider connection string=&quot;Data Source=Data Source=databasehost;User Id=TheID;Password=ThePassword;Initial Catalog=database;
    MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />

    Ialso tried:

    name="default_connection" connectionString="Data Source=databasehost;User ID=theId; Password=ThePassword; Initial Catalog=databasename; " providerName="System.Data.SqlClient" 

    I tried change "data source" ass well to use the same that I use in SQL Server Manager (5.10.80.108,780) and a lot of things but nothing works, I tried every string format I could find in google, My entity framework is pointing to "default_connection", I contacted with the host but they only gave me solutions that I already tried and basically say that it is my code fault and there is nothing they can do.

    thank you for your time and sorry for my bad English

    I finally did it:

    <add name="default_connection" connectionString="Data Source=Remote host ip;User ID=user; Password=password;Initial Catalog=database_name; " providerName="System.Data.SqlClient" />

    Saturday, April 16, 2016 7:27 AM

Answers

  • User1751268424 posted

    Hi,

    Try this (from your first post)

    <add name="default_connection" connectionString="metadata=res://*/App_Code.myApp.csdl|res://*/App_Code.myApp.ssdl|res://*/App_Code.myApp.msl;provider=System.Data.SqlClient;
    provider connection string=&quot;Data Source=Data Source=10.70.15.207,780;User Id=TheID;Password=ThePassword;Initial Catalog=dralks_db;
    MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
    

    Change from "10.70.15.207\SQL2014,780" to "10.70.15.207,780"

    <add name="TunaTumureDbContext" providerName="System.Data.EntityClient" connectionString="metadata=res://*/TunaTumureModel.csdl|res://*/TunaTumureModel.ssdl|res://*/TunaTumureModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=119.81.9.244,780;initial catalog=xxxxxxxx;persist security info=True;user id=xxxxxx;password=xxxxx;MultipleActiveResultSets=True;App=EntityFramework&quot;" />-->
    

    This is mine and it's works. Check your connectionString name on your project, you may use "DefaultConnection" not "default_connection" or wrong name. You can check it on your model context like this:

            public TunaTumureDbContext()
                : base("name=TunaTumureDbContext")
            {

    Have fun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, April 17, 2016 8:24 PM

All replies

  • User753101303 posted

    Hi,

    The first one includes Data Source=Data Source=databasehost. The second one is not for the same context (EF over ADO.NET vs ADO.NET alone) and you could run in other problems as well such as the "remote host" being not available from this machine etc etc...

    When something doesn't work:
    - if you try multiple things you'll likely end up in wasting time in finding "by chance" what works
    - instead stick to one approach, see what is the EXACT error that happens and fix this error

    For example knowing the error message you have with the first string would likely allow to understand if the current problem is really that you have Data Source= twice in the connection string or maybe something else.

    Sunday, April 17, 2016 12:25 PM
  • User1751268424 posted

    Hi,

    Try this (from your first post)

    <add name="default_connection" connectionString="metadata=res://*/App_Code.myApp.csdl|res://*/App_Code.myApp.ssdl|res://*/App_Code.myApp.msl;provider=System.Data.SqlClient;
    provider connection string=&quot;Data Source=Data Source=10.70.15.207,780;User Id=TheID;Password=ThePassword;Initial Catalog=dralks_db;
    MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
    

    Change from "10.70.15.207\SQL2014,780" to "10.70.15.207,780"

    <add name="TunaTumureDbContext" providerName="System.Data.EntityClient" connectionString="metadata=res://*/TunaTumureModel.csdl|res://*/TunaTumureModel.ssdl|res://*/TunaTumureModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=119.81.9.244,780;initial catalog=xxxxxxxx;persist security info=True;user id=xxxxxx;password=xxxxx;MultipleActiveResultSets=True;App=EntityFramework&quot;" />-->
    

    This is mine and it's works. Check your connectionString name on your project, you may use "DefaultConnection" not "default_connection" or wrong name. You can check it on your model context like this:

            public TunaTumureDbContext()
                : base("name=TunaTumureDbContext")
            {

    Have fun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, April 17, 2016 8:24 PM