I am brand spanking new to MVC, leaning MVC4 at the moment due to access to a video tutorial on the subject.
My project will require access to both MSSQL and MySQL. There will be a configuration table in MSSQL that holds the info for various clients, including database connection info. Some will be MSSQL and some will be MySQL with the possibility of different server names, db names, users, and passwords being used to connect to the various databases.
So my default connection and provider info is set to MSSQL in the web.config. I then have a class as follows to connect to the support database to get the connection info:
That code works perfectly, I can retrieve the client database connection info (including provider MSSQL or MySQL) based on an ID passed in from a form.
Now what I would like to do is also have the following:
I want to be able to take the connection info I got from the support table and pass it into the dbData class somehow and have it connect to the correct server/database combo to retrieve the data - but I cannot figure out how to do this. I have tried using SQLConnectionStringBuilder and MySqlConnectionStringBuilder to build a connection string and pass it into the dbData constructor but I keep getting errors when it tries to connect, usually a provider error when I look at the InnerException info. I don't know how to tell it to use the MySql provider instead of the default MSSQL provider.
For reference, here is a sample connection string being passed in for MySql (taken from debug info at break point):
server=localhost;database=clientdb;user id=uid;password=somepassword
But how to tell it to use MySql provider instead of MSSQL? Can anyone help?
My project will require access to both MSSQL and MySQL. There will be a configuration table in MSSQL that holds the info for various clients, including database connection info. Some will be MSSQL and some will be MySQL with the possibility of different server names, db names, users, and passwords being used to connect to the various databases.
So my default connection and provider info is set to MSSQL in the web.config. I then have a class as follows to connect to the support database to get the connection info:
Code:
public class dbSupport : DbContext
{
[indent]public dbSupport() : base("name=DefaultConnection") {}
public DbSet<ClientInfo> ClientInfo {get; set; }[/indent]
}
That code works perfectly, I can retrieve the client database connection info (including provider MSSQL or MySQL) based on an ID passed in from a form.
Now what I would like to do is also have the following:
Code:
public class dbData : DbContext
{
[indent]public dbData(String strConnection) : base(strConnection) {}
public DbSet<ClientData> ClientData {get; set; }[/indent]
}
I want to be able to take the connection info I got from the support table and pass it into the dbData class somehow and have it connect to the correct server/database combo to retrieve the data - but I cannot figure out how to do this. I have tried using SQLConnectionStringBuilder and MySqlConnectionStringBuilder to build a connection string and pass it into the dbData constructor but I keep getting errors when it tries to connect, usually a provider error when I look at the InnerException info. I don't know how to tell it to use the MySql provider instead of the default MSSQL provider.
For reference, here is a sample connection string being passed in for MySql (taken from debug info at break point):
server=localhost;database=clientdb;user id=uid;password=somepassword
But how to tell it to use MySql provider instead of MSSQL? Can anyone help?