首先在 web.config 文件里面增加:
- <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"/>
- </DbProviderFactories>
- </system.data>
C# 使用以下代码就可以了:
- DbProviderFactory oFact = DbProviderFactories.GetFactory("System.Data.SQLite");
- using (DbConnection oConn = oFact.CreateConnection())
- {
- oConn.ConnectionString = "数据库连接字符串";
- oConn.Open();
- oConn.Close();
- }
其实 ASP.NET 程序支持多种数据库使用的也是这个方法。
Powered by Bitrac. 21pt.com by 京ICP备06005887号.