web.config
DatabaseVirtualFile
<configuration> <appSettings> <add key="DatabaseVirtualFile" value="../_database/MyDb.accdb"/> </appSettings> <connectionStrings> <add name="MyConnection_release" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source={physical-file}"/> <add name="MyConnection_debug" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\MyDb.accdb"/> </connectionStrings> ... </configuration>
private string GetConnectionString() { string result = ""; if (Debugger.IsAttached) { result = ConfigurationManager.ConnectionStrings["MyConnection_debug"].ConnectionString; } else { result = ConfigurationManager.ConnectionStrings["MyConnection_release"].ConnectionString; string dbFile = ConfigurationManager.AppSettings["DatabaseVirtualFile"]; string file = Server.MapPath(dbFile); result = result.Replace("{physical-file}", file); } return result; }
System.Data.OleDb
OleDb
using System.Data.OleDb; ... public static string GetNodes(int parentId) { //- Inits --------------------------------------------------------------------------------- string result = ""; OleDbConnection conn = new OleDbConnection(_connectionString); conn.Open(); //- Call GetNodes Query ------------------------------------------------------------------- OleDbCommand cmd = new OleDbCommand("GetNodes", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("ParentId?", parentId); OleDbDataAdapter da = new OleDbDataAdapter(cmd); NodesDataSet.NodesDataTable t = new NodesDataSet.NodesDataTable(); da.Fill(t); // other code here //- Clean Up ------------------------------------------------------------------------------ cmd.Dispose(); conn.Close(); conn.Dispose(); return result; }