New Posts New Posts RSS Feed: Changing the Connection String at Runtime
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Changing the Connection String at Runtime

 Post Reply Post Reply
Author
Sakar SR View Drop Down
Newbie
Newbie
Avatar

Joined: 21-Jul-2010
Location: India
Posts: 39
Post Options Post Options   Quote Sakar SR Quote  Post ReplyReply Direct Link To This Post Topic: Changing the Connection String at Runtime
    Posted: 01-Mar-2012 at 6:58am
How to change the directory and path of my database location ?

string datapath = @"'D:\SQLite Database\eFillerDB\eFilerDB.DAT";
string metadata = @"metadata= res://*/eFiler.csdl|//*/eFiler.ssdl|res://*/eFiler.msl;
                                provider=System.Data.SQLite;
                                provider connection string='data source='" + datapath;
string conn = metadata;

var config = IdeaBlade.Core.IdeaBladeConfig.Instance;
var keys = config.EdmKeys;
            
keys.Add(
                new EdmKeyElement
                {
                    Name = "eFilerDBEntities",
                    LogTraceString = false
                    Connection = conn                       
                });

When i try to run this code i get an runtime error saying to check the connection string.

my requirement is only to change the path and directory of the database location at runtime . what is wrong in the above code.

Please explain, to correct this problem.




Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 782
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 01-Mar-2012 at 6:13pm
Hi Sakar,
 
It might be possible that your connection is sting is malformed. (I see opening single quotes on datapath, but no closing)
A good starting point would be looking at the connectionString created in your Model's app.config file (i.e. assuming you created your model based on an existing database)
For instance, I've tried the following without any issues: (I've copied the connectionString from app.config)
 
EdmKeyElement edmKey = new EdmKeyElement("NorthwindIBEntities");
edmKey.Connection = "metadata=res://*/NorthwindModel.csdl|res://*/NorthwindModel.ssdl|res://*/NorthwindModel.msl;provider=System.Data.SqlClient;provider connection string='data source=.;initial catalog=NorthwindIB;integrated security=True;multipleactiveresultsets=True;App=EntityFramework'";
IdeaBladeConfig.Instance.EdmKeys.Add(edmKey);
 
Also, you might want to use DataSourceExtensions.
You can find more details about DataSourceExtensions in the DevForce Resource Center.
 
Regards,
   Silvio.


Edited by sbelini - 01-Mar-2012 at 6:44pm
Back to Top
Sakar SR View Drop Down
Newbie
Newbie
Avatar

Joined: 21-Jul-2010
Location: India
Posts: 39
Post Options Post Options   Quote Sakar SR Quote  Post ReplyReply Direct Link To This Post Posted: 02-Mar-2012 at 12:07am
Hi Sbelini,

Thank you for the help, i solved the problem

Have a nice day

Regards,
Sakar


Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down