Entity Framework changing connection string with c# -


i have app connection string changes per user , machine. said have made test connection string testing. once working add dynamic connection string.

after research have figured out there problem connection string.

if please tell me wrong appreciate it.

var s = @"metadata=res://*/procurementmodel.csdl|res://*/procurementmodel.ssdl|           res://*/procurementmodel.msl;provider=system.data.sqlclient;           provider connection string=&';data source=james-desktop\sqlexpress;initial catalog=mydatabase;persist security info=true;user id=user;password=*****;multipleactiveresultsets=true;app=entityframework&';"; 

update:

public procurementcontext() {     var s =             @"metadata=res://*/procurementmodel.csdl|res://*/procurementmodel.ssdl|             res://*/procurementmodel.msl;provider=system.data.sqlclient;             provider connection string=&';data source=james-desktop\sqlexpress;initial catalog=mydatabase;persist security info=true;user id=jd;password=p@ssw0rd;multipleactiveresultsets=true;app=entityframework&';";      _connectionstring = s; } 

getting data:

public list<procurement> parcellistbyuser(string username) {     using (var context = new procuremententities(_connectionstring))     {         return context.procurements.where(p => p.username == username).tolist();     } } 

constructor:

public procuremententities(string connectionstring)     : base(connectionstring) { } 

error message:

format of initialization string not conform specification starting @ index 165.

configuration:

the configuration of procurement

public class procurementconfiguration:dbconfiguration {     public procurementconfiguration()     {         setexecutionstrategy("system.data.sqlclient", () => new sqlazureexecutionstrategy());         setdefaultconnectionfactory(new sqlconnectionfactory(connectionstrings.localconnectionstring));     } } 

i think issue in connection string. i've made same thing , have function create connection string in automatic way.

the code:

    public static string getconnectionstring()     {         // build provider connection string configurable settings         string cn = "server=" + mdlimpostazioni.p.dbserver;         cn += ";database=" + mdlimpostazioni.p.dbname;         cn += ";uid=" + mdlimpostazioni.p.dbuser;         cn += ";pwd=" + mdlimpostazioni.p.dbpassword + ";";         var providersb = new sqlconnectionstringbuilder(cn);         var efconnection = new entityconnectionstringbuilder();         // or config file based connection without provider connection string         efconnection.provider = "system.data.sqlclient";         efconnection.providerconnectionstring = providersb.connectionstring;         // based on whether choose supply app.config connection string constructor         efconnection.metadata = @"res://*";  //-----> important         return efconnection.tostring();     } 

in way, pass return value db context constructor, in code. constructor is:

public partial class entities : dbcontext {     public entities(string nameorconnectionstring)         : base(nameorconnectionstring)     {      }      public void close()     {         this.dispose();     } } 

try , ask if have problem.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -