Ent Library. Substitute data from app.config?

M

malice

I have been searching the internet for 12+ hours on how to do this. At this point I'm about to give up. I am using VB .Net 2.0 with the enterprise library jan 2006 release. This is my first time using it and I'm a novice to .Net. I am using the data access quickstart solution and I just started adding my own forms and stuff to it. I got my sql query to work and populate a dataview on my new form with just a few lines of code. Here is my problem :
I work in an environment where we have 2000+ MS SQL servers. My app will use a text box to get the name of the server you wish to connect to and retrieve data. The ent lib seems to have the server name hard coded in the app.config file. When I use my createdatabase method how do I substitute a different server name from the one in the app.config? I need this to be as simple as possible becase I am a novice and might not be able to implement something that is too complex.


--------------= Posted using GrabIt =----------------
------= Binary Usenet downloading made easy =---------
-= Get GrabIt for free from http://www.shemes.com/ =-
 
C

Cor Ligthert [MVP]

Malice,

If there is one type of file not hardcoded than it are config files.

Do you not see that?

Cor
 
J

Jay B. Harlow [MVP - Outlook]

Malice,
The CreateDatabase method & the Enterprise Library assume that you have
*all* the servers that you can connect to listed in the app.config.

Using CreateDatabase() will read the "default" connectionsetting, while
using CreateDatabase(name) will read the specified connection setting.

If using the Enterprise Library is a "Requirement", then you have 2 options:
1) list all 2000+ MS SQL servers in the connection setting section of the
app config. I would recommend you use the configSource attribute in your
app.config.
2) Modify CreateDatabase to accept the SQL server name and/or the connection
string.

I would probably opt for the first over the second, as it allows greater
control over the connection string itself, the user only needs to know the
"key" to the connection string, which may or may not be the server name
itself. Of course the first entails a lot of entries in the app.config,
hence the suggestion of the configSource attribute. The second may be a
maintenance issue as newer versions of the Enterprise Library are
released...

For information on using configSource see "Using .NET's configSource
attribute" at
http://blogs.msdn.com/tomholl/archive/2006/04/02/entlib2externalconfig.aspx

If using the Enterprise Library is not a "Requirement", then you have 2
options:
1) list all 2000+ MS SQL servers in the connection setting section of the
app config. I would recommend you use the configSource attribute in your
app.config.
2) Build the required connection string then passing this to a SqlConnection
object.


Again the first allows greater control over the connection string itself,
while the second would probably more code yet smaller app.config file...

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


|I have been searching the internet for 12+ hours on how to do this. At this
point I'm about to give up. I am using VB .Net 2.0 with the enterprise
library jan 2006 release. This is my first time using it and I'm a novice to
..Net. I am using the data access quickstart solution and I just started
adding my own forms and stuff to it. I got my sql query to work and populate
a dataview on my new form with just a few lines of code. Here is my problem
:
| I work in an environment where we have 2000+ MS SQL servers. My app will
use a text box to get the name of the server you wish to connect to and
retrieve data. The ent lib seems to have the server name hard coded in the
app.config file. When I use my createdatabase method how do I substitute a
different server name from the one in the app.config? I need this to be as
simple as possible becase I am a novice and might not be able to implement
something that is too complex.
|
|
| --------------= Posted using GrabIt =----------------
| ------= Binary Usenet downloading made easy =---------
| -= Get GrabIt for free from http://www.shemes.com/ =-
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top