我正在使用Microsoft.Practices.EnterpriseLibrary数据库工具,我只使用连接字符串信息创建新数据库时遇到问题.
理想情况下,我想做以下事情:
Database dbEngine = DatabaseFactory.CreateDatabase( "Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;");
是否可以仅使用连接字符串创建数据库?
如果是这样,怎么能实现呢?
你也可以
Database mydb = new EnterpriseLibrary.Data.Sql.SqlDatabase("connection string here");
并且您将保留Database对象的多功能性,但使用连接字符串创建它.
我正在动态地构建一个连接字符串,其中ConnectionString位于我的.config中
Database configdb = DatabaseFactory.CreateDatabase("ConnectionString"); DbConnectionStringBuilder sb = configdb.DbProviderFactory.CreateConnectionStringBuilder(); // Set the Connection String fields. sb["Data Source"] = targetServer; sb["Initial Catalog"] = targetDb; sb["User ID"] = username; sb["Password"] = password; sb["Connect Timeout"] = dbTimeout; GenericDatabase newDb = new GenericDatabase(sb.ToString(), configdb.DbProviderFactory); Database db = newDb;