I am using the Microsoft.Practices.EnterpriseLibrary Database tools and I'm having trouble creating a new database using just the connection string information.
Ideally I would like to do the following:
Database dbEngine = DatabaseFactory.CreateDatabase(
"Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;");
Is it possible to create a database using just the connection string?
If so, how can it be achieved?
I discovered that you can use the following command ...
not quite as versatile as the Database object but it works for my purpose.
Thanks everyone!
Er... That's because CreateDatabase expects the name of a connection string (as specified in your app's config file), not the connection string itself.
I am building a connection string on the fly dynamically with the following where ConnectionString is in my .config
It's solved my problem. I have a single web app using many database, according to the different subdomain in the url to connect to the different database. such as:
abc.test.com ------>using the Db_projectABC
def.test.com ------>using the db_ProjectDEF
I use url-rewrite to parse the subdomain name, and use the subdomain name to chose it's database connection string which stored in the main database.
Thanks
You can also do
and you'll retain the versatility of the Database object, but create it with a connection string.