ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

.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
تم إضافة السؤال من قبل Fakhr -e-alam , Application Developer , Al Dhafra Cooperative Society (ADCS)
تاريخ النشر: 2013/10/25
Houssem Gharsallah
من قبل 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. 

مستخدم محذوف‎
من قبل مستخدم محذوف‎

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

Usama Elyamany
من قبل 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
من قبل 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 

. . . . . 

Adnan Hamdani
من قبل Adnan Hamdani

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);    }

 

 

المزيد من الأسئلة المماثلة