Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

.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 added by Fakhr -e-alam , Application Developer , Al Dhafra Cooperative Society (ADCS)
Date Posted: 2013/10/25
Houssem Gharsallah
by 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. 

Deleted user
by Deleted user

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

Usama Elyamany
by 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
by 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