Dynamic connection string for a strongly typed dataset

I have an asp.net nTier application. The data access layer is a strongly typed DataSet consisting of several DataTables with DataAdapters. When a user logs in, they choose which database to connect to (from the table in the membership database). I need to pass the selected connection string to a DataSet that will remain the same for these users until they log in again.

I think the answer might be to create a partial class of the DataSet where I can pass the connection string to the constructor. I am not sure how to do this.

Greetings

+6
string dynamic dataset connection
source share
2 answers

You can do this with a partial class.

Assuming your typed dataset is called HurrDurr:

public partial class HurrDurr { public HurrDurr(string connex) { this._connection = new global::System.Data.SqlClient.SqlConnection(); this._connection.ConnectionString = connex; } } 

_The connection is initialized only if it is null the first time you access the internal property of Connection.

+3
source share

Finally reached the end. In the new module, I created a partial class for the table adapter in which I needed to change the connection string, one error that I made initially did not indicate the correct namespace.

The following is a partial class that allowed me to dynamically change the connection string of one of my table adapters for a table called tblOptions:

 Namespace ds1TableAdapters Partial Public Class tblOptionsTableAdapter Sub ChangeConnString(ByVal newConn As String) Me._connection.ConnectionString = newConn End Sub End Class End Namespace 

Thanks for the help Will, he made me move in the right direction.

+3
source share

All Articles