The Webmatrix.data of WebMatrix
WebMatrix Data Access Series contents:
- WebMatrix data Access
- The Webmatrix.data of WebMatrix
- The Webmatrix.data of WebMatrix
- The reform of WebMatrix Webmatrix.data
In the previous article, I simply took a look at how the WebMatrix Web opened up things to make database crud simple. The database access component, Webmatrix.data, is a lightweight, dynamic Data access component that Microsoft has built for WebMatrix. You can use a single reference WebMatrix.Data.dll step set as a lightweight component for data access. This is said to be lightweight, because the component does not pay the storage process, things, in the final analysis, it is specifically designed for SSCE.
The following is a brief look at how Webmatrix.data cross-database platform incident.
1.SQL Server 2005/2008 Pay
In the past, God horse Cross-database to pay the most people have seen the most than the three-tier through the replacement of the DAL DLL, the Factory mode connection settings file relies on injection to implement the database switching. But Webmatrix.data does not have to do that now, the simplest way is to set the File Settings section connectionstring specific settings. The following example is the use of a console step in the ConnectionString under App. Config as follows:
<connectionstrings><add name= "MySQLdb" connectionstring= "server=.;D Atabase=mytestdb; User Id=sa; password=******; "Providername=" System.Data.SqlClient "/></connectionstrings>
Set the file settings so you can access the data like this:
SQL Server var db = Database.open ("
The above code is similar to access to the SSCE database, the difference is that it is necessary to provide the corresponding database settings adjacent strings, Database.open to pass in a named adjacent string "MySQLdb".
It is important to note that if you omit the providername in connectionstrings, you will throw a very:
However, this can be written in appsettings to prevent a very thrown to normal access to the database:
<appSettings> <add key= "Systemdata:defaultprovider" value=http://www.cnblogs.com/microred/archive/ 2012/04/04/"System.Data.SqlClient"/> </appSettings>
If you do not provide providername in connectionstrings, nor do you set providername in appsettings, then Webmatrix.data will use SSCE's SQL to provide the pace (system.data.sqlserverce.4.0) by default. As for why, the next article will reveal.
Similarly, you can take advantage of database.openconnectionstring (string connectionString) and its overloaded Essentials openconnectionstring (String connectionString , string providerName) to create a database instance by passing in a contiguous string with an undefined name.
2.Oracle of pay
Oracle's Test I chose Odp.net (Oracle Data Provider for. NET). Period, to understand a problem (using a lazy writing), if connectionstrings like this set:
<add name= "myoracle" connectionstring= "Data source=oradb; User Id=testdb; password=*****; " Providername= "Oracle.DataAccess.Client"/>
ORADB is set in Tnsnames.ora, using the traditional method without any problems:
var data = Http://www.cnblogs.com/Microred/archive/2012/04/04/new DataTable (); using (oracleconnection connection = new OracleConnection (connectionstring)) { using (oracledataadapter adapter = new OracleDataAdapter ("SELECT * from TestDB. Sys_dict a ", connection)) { adapter. Fill (data); } }
But there are problems with Webmatrix.data access:
var db = Database.open ("myoracle"); var list = db. Query ("SELECT * from TestDB.") Sys_dict a "); foreach (var item in list) { Console.WriteLine (item. dict_name); }
TAG: The Webwebmatrix
The Webmatrix.data of WebMatrix