469,623 Members | 1,525 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,623 developers. It's quick & easy.

Passing LINQ a dynamic connection string

VS2008, .NetFramework 3.5 SP1:

I have built a LINQ data access layer project. When the LINQ data context
was built over an existing SQL2005 database, the connection string for that
database was correctly, automatically, placed into the Settings for the LINQ
project. It works, but it's a "static" connection string.

I would like to be able to use this one LINQ data access layer against both
test and production databases without having to manually change and
recompile the project's connection string each time. Since this is a data
access layer project, the functions within it are called by the User
application project. The User application project has the test or
production connection string within it's settings.

Is there a way to pass the User connection string to the LINQ data access
layer? I would even consider passing the connection string on each function
call to the LINQ project, but my first attempt was unsuccessful, because the
LINQ connection string is ReadOnly.

Public Shared Function GetModuleRowsActiveBoot(ByVal strConnectionString
As String) As DataTable
Dim dt As New DataTable
Try
Dim dc As New dcSecurityDataContext
Global.SecurityLinq.My.MySettings.Default.Security ConnectionString
= strConnectionString

The last statement above is in error because
Global..SecurityConnectionString is ReadOnly.

Anyone tried doing this?
Oct 8 '08 #1
1 6127
On Oct 8, 2:16 pm, "Dean Slindee" <slin...@charter.netwrote:
VS2008, .NetFramework 3.5 SP1:

I have built a LINQ data access layer project. When the LINQ data context
was built over an existing SQL2005 database, the connection string for that
database was correctly, automatically, placed into the Settings for the LINQ
project. It works, but it's a "static" connection string.

I would like to be able to use this one LINQ data access layer against both
test and production databases without having to manually change and
recompile the project's connection string each time. Since this is a data
access layer project, the functions within it are called by the User
application project. The User application project has the test or
production connection string within it's settings.

Is there a way to pass the User connection string to the LINQ data access
layer? I would even consider passing the connection string on each function
call to the LINQ project, but my first attempt was unsuccessful, because the
LINQ connection string is ReadOnly.

Public Shared Function GetModuleRowsActiveBoot(ByVal strConnectionString
As String) As DataTable
Dim dt As New DataTable
Try
Dim dc As New dcSecurityDataContext
Global.SecurityLinq.My.MySettings.Default.Security ConnectionString
= strConnectionString

The last statement above is in error because
Global..SecurityConnectionString is ReadOnly.

Anyone tried doing this?
That code appears to be incorrect. Doesn't the DataContext derived
class take the connection string in its constructor? In any event,
you can store the connection string in a configuration file of xml
file and read it from there. Since it is just a string, you could
also create one dynamically at runtime or let the user choose one.
There are any number of ways to handle this.

Chris
Oct 9 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Ronald S. Cook | last post: by
28 posts views Thread by Marc Gravell | last post: by
11 posts views Thread by =?Utf-8?B?U3RlZmFuIFdpbGhlbG0=?= | last post: by
4 posts views Thread by BeSharp | last post: by
1 post views Thread by Lacutas | last post: by
1 post views Thread by john | last post: by
3 posts views Thread by TisMe | last post: by
6 posts views Thread by Plissskin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.