Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

.net programming approach to connect database dynamically (ACCESS or SQL Server)?

I have2 clients with same reuirements but the only difference is1 of then want to have MS ACCESS and the other want to use MS SQL SERVER. I want to develop it at once and connect database DBMS dynamically

user-image
Question ajoutée par Fakhr -e-alam , Application Developer , Al Dhafra Cooperative Society (ADCS)
Date de publication: 2013/10/25
Houssem Gharsallah
par Houssem Gharsallah , Software Architect , NOMD Technologies

Change the connection string at runtime. 

 

TIP: You can also economize code by using a database driver that works on many databases such as OLE DB. 

Utilisateur supprimé
par Utilisateur supprimé

MS SQL , its working in MS ERP like GP And AX in one layer

Usama Elyamany
par Usama Elyamany , Product Manager , Brmaja

Easly with bridge like ODBC and make a DSN file for each database so you can connect swaply

karim marouf
par karim marouf , Team Manager , OASYS

I do the following:

ConnexionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data source=" & "C:\\Ophtalmo\\Ophtalmo.accdb"  My.Settings("OphtalmoConnectionString") = ConnexionString

 

I build the connexionstring at runtime depending on MS-ACCESS or SQL-Server.

 

But keep in mind that th connexion is not the only issue that you will be facing !

 

Some querries will not work on both DBMS at the same time, for exemple :

 

You need to handle the compatibility for  "  and '  string delimiters 

Dates values are not calculated the same way 

. . . . . 

you need to create new table in sql server will be better and name it "user_db" with fields (username , db_type , connnections string), in the code select * from user_db where username = @username

if (str_db_type = "sql")

{

sql_con sqlconnection = new sqlconnection(connection_string);

}

else

{

acc_con oledbconnection = new oledbconnection(connection_string );

}

 then pass this connection to the function of subroutine like

 ExecuteScalarExample(sql_con);or you mayExecuteScalarExample(acc_con);

 public static void ExecuteScalarExample(IDbConnection con) {        IDbCommand com = con.CreateCommand();        com.CommandType = CommandType.Text;        com.CommandText = "SELECT COUNT(*) FROM Employees";

        int result = (int)com.ExecuteScalar();        Console.WriteLine("Employee count = " + result);    }

 

 

More Questions Like This