Vista or later systems must have System Administrator privileges to execute the following code. Sqlite.net uses 1.0.66.0, supports the ado.net EF data model,: http://sourceforge.net/projects/sqlite-dotnet2/files/SQLite%20for%20ADO.NET%202.0/
During deployment, make sure that system. Data. SQLite. dll and system. Data. SQLite. LINQ. dll are in the input directory of the project. That is, the directory where your program EXE file is located.
Using system. configuration;
Using system. xml. LINQ;
Using system. kerberiseservices. Internal;
VaR d = configurationmanager. openmachineconfiguration (). filepath;
Xelement Xe = xelement. Load (d );
VaR dd = Xe. element ("system. Data"). element ("dbproviderfactories"). Elements ("add ");
If (DD. Where (MD => Md. Attribute ("name"). value. Equals ("SQLite data provider"). Count () = 0)
{
Publish objpub = new publish ();
Objpub. gacremove ("system. Data. SQLite. dll ");
Objpub. gacremove ("system. Data. SQLite. LINQ. dll ");
Objpub. gacinstall ("system. Data. SQLite. dll ");
Objpub. gacinstall ("system. Data. SQLite. LINQ. dll ");
Xe. element ("system. Data"). element ("dbproviderfactories"). Add (New xelement ("add ",
New xattribute ("name", "SQLite data provider"), new xattribute ("invariant ",
"System. Data. SQLite"), new xattribute ("Description", ". NET Framework data provider for SQLite "),
New xattribute ("type", "system. Data. SQLite. sqlitefactory, system. Data. SQLite, version = 1.0.66.0, culture = neutral, publickeytoken = db937bc2d44ff139 ")
));
Xe. Save (d );
}
The following provides a custom database connection method for the User-Defined ado.net EF:
Public entityconnection getentityconnection ()
{
Entityconnectionstringbuilder ecsb = new entityconnectionstringbuilder ();
Ecsb. metadata = string. format (@ "res: // */{0 }. CSDL | res: // */{0 }. SSDL | res: // */{0 }. MSL "," model1 ");
Ecsb. provider = "system. Data. SQLite ";
Ecsb. providerconnectionstring = @ "Data Source = data. DB; Password = admin ";
Entityconnection EC = new entityconnection (ecsb. tostring ());
Return EC;
}
Use Time:
Dataentities de = new dataentities (getentityconnection ());
Datagrid1.itemssource = de. usertable;