473,386 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 6289
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Ronald S. Cook | last post by:
I've always been taught that stored procedures are better than writing SQL in client code for a number of reasons: - runs faster as is compiled and lives on the database server - is the more...
28
by: Marc Gravell | last post by:
In Linq, you can apparently get a meaningful body from and expression's .ToString(); random question - does anybody know if linq also includes a parser? It just seemed it might be a handy way to...
11
by: =?Utf-8?B?U3RlZmFuIFdpbGhlbG0=?= | last post by:
Hello, played a little with orcas and went into a problem by building dynamic queries. I want to build a dynamic where clause but only with parameters that are not empty =(TextBox.Text != "")....
4
by: BeSharp | last post by:
I recently stumbled across a pretty interesting LINQ to SQL question and wonder, whether anybody might have an answer. (I'm doing quite some increasing LINQ evangelism down here in Germany.). ...
1
by: Lacutas | last post by:
Hi I'm having some problems getting a dynamic LINQ query to work on my DataSet. The idea is that a user selects certain criteria, and then the LINQ query filters through the dataset making the...
1
by: john | last post by:
I'm trying to build a LINQ expression that will use a dynamic construction of a LIKE statement in the WHERE clause, it would look something like this in SQL: WHERE TaskGroup Like "*00*" OR...
3
by: TisMe | last post by:
Hi All, I am using Linq to SQL dataclass for my website application. This was working AOK, but then I deleted and recreated the dataclass (Seemed the simpliest way of updating the class to...
6
by: Plissskin | last post by:
I need to create an "ad-hoc" filtering page in a web app we are building. The page would display a number of drop down lists, text boxes, and radio lists and allow the user to select (enter) some...
2
by: giddy | last post by:
hi, Yes its a design question again. =) If I have something like: class Person { //functions: static Person GetAllPersons(); static Person Search(string field,string value);
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.