views:

104

answers:

1

Hi,

I have developed a windows form application using VB.Net with data access layer using LINQ-SQL. I want to allow the database to be configured from the application. I have created a form for input and save the input details in an XML file.

I need to know how to configure the LINQ to start using the new configured database on startup. I have read in one of the threads here about dynamic allocating the connection string with the following solution to include in every file where the data context is instantiated.

MyDataClassesDataContext db = new MyDataClassesDataContext(dynamicConnString);


protected void LinqDataSource_ContextCreating(object sender, LinqDataSourceContextEventArgs e)
{
    e.ObjectInstance = new MyDataClassesDataContext (dynamicConnString);
}

Would this work for my scenario? In what format the connection string needs to be and how to include the password and location of database server?

Also one more question. I believe the LINQ takes care of freeing up the resources when the DataContext is destroyed. So I don’t need to worry about freeing up resources when the application exists completely (using Application.Exit()). Just want to confirm if this is true.

Thanks in advance for any help.

A: 

The connection string needs to be in the correct format for ADO.Net. If you have doubts, see this link for examples.

Chris Dunaway