Connect to DB using config settings and user input

Oct 9, 2007 at 8:07 PM
Using DAAB, I would like to retrieve the server and database name from the connectionString in app.cfg and then add the uid and pwd as entered by users.

This is what I came up with but it seems naive:

Database db = DatabaseFactory.CreateDatabase();

DbConnection dbConnection = db.CreateConnection();
dbConnection.ConnectionString += String.Format( "uid={0};pwd={1};" , _logon.Name, _logon.Password);
dbConnection.Open();

DbCommand dbCommand = db.GetStoredProcCommand("somestoredproc");
db.AddInParameter(dbCommand, "@Name", DbType.AnsiString, _logon.Name);
dbCommand.Connection = dbConnection;

SqlDataReader dr = (SqlDataReader)dbCommand.ExecuteReader(CommandBehavior.CloseConnection);

Can anyone offer a better solution?