Pages

Thursday, October 01, 2009

Setting the Connection for LinqDataSource

Below is the summary of how to set a custom connection for LinqDataSource. It does not accept any parameters and creates a data context using the default constructor. If you want to set another connection string, set the ObjectInstance like this:


Protected Sub LinqDataSource1_ContextCreating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceContextEventArgs) Handles LinqDataSource1.ContextCreating

    'Pass the custom connection string.
    Dim db As New DBADMDataContext(DBADMDataContext.getConnectionString())

    e.ObjectInstance = db

End Sub

linqdatasource runtime connection string - Application Forum at ObjectMix.com
By default, LinqDataSource create data context by using default
constructor. If you want to use specific connection, I think you can create
data context object by yourself, and assign the object to the
ObjectInstance property in ContextCreating event.

Please refer to the following document. There is a simple about how to
specify connect string for LinqDataSource by yourself.
http://msdn2.microsoft.com/en-us/lib...rols.linqdatas
ource.contextcreating.aspx
[LinqDataSource..::.ContextCreating Event]

No comments: