IntegrationEnterprise LibraryConnect to and operate SQLite
Enterprise Library is one of our common frameworks. You can download Enterprise Library 5.0.msi from http://entlib.codeplex.com. After installation, the source code and chm documents are provided. Many of the ideas are worth studying by our programmers.
The data access component in the enterprise database is also one of our Common Data Access Components. By default, the component supports database access from SQL Server and Oracle, and supports custom extensions.
Use the enterprise database to operate SQLite Databases
Enterprise Library Contrib is an extension component of the Enterprise Library. It extends many functions of the enterprise database. The expansion of the database includes the access to SQLite, so that we can operate the SQL SERVER,
The code can be easily transitioned to SQLite without much modification. You can also download the latest entlibcontrib-5.0.505.0-2011-10-29-bin.zipon http://entlib.codeplex.com.
SQLite. NET is also a data access component.
The System. Data. SQLite is like the System. Data. SqlClient that comes with. NET. It contains common data access objects such as connection and command, but they all have a prefix sqlite.
: Bytes.
This operation is required only when SQLite. NET is used to access SQLite.
SQLite Expert is a visual database management tool.
Allows you to create, edit, copy, and extract data on the SQLite server. SQLite Expert supports SQLite features of all graphical interfaces. It includes a visual query generator, an SQL editing and syntax highlighting, and automatic completion of code,
Powerful table and view design and import/export functions. SQLite Expert is now divided into two versions: Free Personal Edition and paid Professional Edition.
Connection Method
First. config or app. add the following configuration to config. In the connectionstring configuration section, the db is the SQLite database file, which is placed in the App_Data directory of the Web application. | DataDirectory | this indicates the location of this directory,
The file name is followed, and the rest is that we use the Enterprise Library to access SQL Server.
<configuration>
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings,
Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null />
</configSections>
<dataConfiguration defaultDatabase="
">
<providerMappings>
<add databaseType="EntLibContrib.Data.SQLite.SQLiteDatabase, EntLibContrib.Data.SqLite, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null"
name="System.Data.SQLite" />
</providerMappings>
</dataConfiguration>
<connectionStrings>
<add name="sqlite" connectionString="Data Source=|DataDirectory|\db;Pooling=true;FailIfMissing=false"
providerName="System.Data.SQLite" />
</connectionStrings>
</configuration>
Use SQLite. NET to access SQLite
Add a reference to System. Data. SQLite. Add the following configuration in the configuration file (web. config or app. config,
That is, to add a creation source for DbProviderFactory, you can use the DbProviderFactory class in the code to create the SQLite Data Access Object.
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite"/>
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite"
type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
</DbProviderFactories>
</system.data>
Access SQLite using original ecology ADO. NET
Original access means to directly open the database with the connection and command objects, and then open the connection for data operations.
DbProviderFactory fact = DbProviderFactories.GetFactory("System.Data.SQLite");
using (DbConnection conn = fact.CreateConnection())
{
conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["sqlite"].ConnectionString;
conn.Open();
DbCommand comm = conn.CreateCommand();
comm.CommandText ="select * from customer";
comm.CommandType = CommandType.Text;
using (IDataReader reader = comm.ExecuteReader())
{
while (reader.Read())
{
Response.Write(reader[0]);
}
}
}