Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Microsoft Enterprise Libraries Database connection 1

Status
Not open for further replies.

tekkerguy

Programmer
Nov 16, 2005
196
US
The Microsoft Ent Lib Database function seems to only accept a Key setting from the app.config file.

I need to pass in my own connection string that is built up from user input.

Does anyone know of another function in Ent Lib that will accept my own string?


When I try to use mine in the database command, it gives me:

Code:
The requested database Data Source = [i]server[/i];Initial Catalog = [i]catalog[/i];Persist Security Info=True; User ID = [i]userlogin[/i] ; Pwd = [i]pwd[/i]; is not defined in configuration.

So how can I just pass my own connection string?

Or should I just use the System.Sql methods? (I'd prefer to use the ent lib though)
 
My understanding is that you'd need to write a custom class that extends the DatabaseFactory class to return a Database object.

Unfortunately, the documentation for EntLib is at work, and the Vista machine at home won't let me open the CHM file. :(

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Chip, you use Vista?

tekkerguy - use the msdn website to search for the DatabaseFactory class.

msdn.microsoft.com
 
OK found it at work.

You inherit from Database, and then create a new constructor that lets you pass in a connection string:
Code:
public MyShinyDatabase(string connectString)
   : this(connectString, SqlClientFactory.Instance)
{
}
There are then many different methods that you need to override, that I can't get into here. But you can read about them by searching in the EntLib documentation for "Adding a New Application Block Database Provider"


JurkMonkey - yes, I have Vista Business at home. I can't say I love it. But it works. Sortof.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Actually, I like my Mac better.
:)

But developing for the Mac is a pain -- not only because of having to learn Objective C, but because Apple keeps making radical changes to the application stack.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top