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.

Ent. Library substitute data from app.config
Radikal08
Dim connectionString As String = "Initial Catalog=CCTVWare;" _
& "Data Source=(T9975APS0001\PRD1);Integrated Security=SSPI;"
Dim db As Database = New SqlDatabase(connectionString)
db = DatabaseFactory.CreateDatabase()
Dim sqlCommand As String = "select camid, camdesc, compname " & _
"from cameras as c " & _
"inner join computers as p " & _
"on c.lruid = p.compid "
Dim dbCommandWrapper As DbCommand = db.GetSqlStringCommand(sqlCommand)
' DataSet that will hold the returned results
Dim productsDataSet As DataSet = Nothing
productsDataSet = db.ExecuteDataSet(dbCommandWrapper)
' Note: connection was closed by ExecuteDataSet method call
Return productsDataSet
Craig Selbert
MAizawa
You won't be able to use DatabaseFactory.CreateDatabase() in that way, because it expects the connection string to be available from an IConfigurationSource.
If you will only be using this with SQL Server, which appears to be the case, I recommend creating the SqlDatabase object directly, which will take a connection string in its constructor.
Database db = new SqlDatabase(yourConnectionString);
You can build your connection string dynamically using SqlConnectionStringBuilder and then call ToString() on it and pass that connection string into SqlDatabase.
Here is a tutorial I wrote that talks about SqlConnectionStringBuilder:
Builder Design Pattern Part I - DBConnectionStringBuilder and SqlConnectionStringBuilder in ADO.NET 2.0
Here is an article I wrote that talks about the 3 ways to work with Enterprise Library 2.0 DAAB:
Enterprise Library 2.0 Data Access Application Block
As an FYI, Enterprise Library has their own set of message boards where you can ask questions:
http://www.gotdotnet.com/codegallery/messageboard/messageboards.aspx id=295a464a-6072-4e25-94e2-91be63527327
Hope this helps,
Dave