(1) download SQLite (sqlite-netFx40-setup-bundle-x64-2010-1.0.83.0) from the following URL ):
Http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki
Using: using system. Data. SQLite;
Add code: sqliteconnection. createfile (datasource); the following error is reported during running (the first time you use C #, please help analyze the cause of the error ):
System. badimageformatexception not processed
Message = failed to Load file or assembly "system. Data. SQLite, version = 1.0.83.0, culture = neutral,
Publickeytoken = db937bc2d44ff139 "or one of its dependencies. Attackers try to load programs with incorrect format.
Source = usesqlite
Filename = system. Data. SQLite, version = 1.0.83.0, culture = neutral, publickeytoken = db937bc2d44ff139
Fusionlog === pre-binding status information ===
Log: User = yonghang-PC \ yonghang
Log: displayname = system. Data. SQLite, version = 1.0.83.0, culture = neutral, publickeytoken = db937bc2d44ff139
(Fully-
Specified)
Log: appbase = file: // E:/source/PC/usesqlite/bin/debug/
Log: initial privatepath = NULL
Call the Assembly: usesqlite, version = 1.0.0.0, culture = neutral, publickeytoken = NULL.
===
Log: This binding starts from loading the context by default.
Log: The application configuration file is not found.
Log: Use the host configuration file:
Log: use the computer configuration file c: \ windows \ Microsoft. NET \ framework \ v4.0.30319 \ config \ machine. config.
Log: reference after policy: system. Data. SQLite, version = 1.0.83.0, culture = neutral, publickeytoken = db937bc2d44ff139
Log: download the new URL File: // E:/source/PC/usesqlite/bin/debug/system. Data. SQLite. dll.
Error: failed to complete assembly installation (hR = 0x8007000b ). Detection termination.
Stacktrace:
In usesqlite. form1.createsqlitedatabase ()
In usesqlite. form1.. ctor () Location E: \ source \ PC \ usesqlite \ form1.cs: Row 22
In usesqlite. program. Main () Location E: \ source \ PC \ usesqlite \ Program. CS: Row 18
In system. appdomain. _ nexecuteassembly (runtimeassembly assembly, string [] ARGs)
In system. appdomain. executeassembly (string assemblyfile, evidence assemblysecurity, string [] ARGs)
In Microsoft. visualstudio. hostingprocess. hostproc. runusersassembly ()
In system. Threading. threadhelper. threadstart_context (object state)
In system. Threading. executioncontext. Run (executioncontext, contextcallback callback, Object
State, Boolean ignoresyncctx)
In system. Threading. executioncontext. Run (executioncontext, contextcallback callback, Object
State)
In system. Threading. threadhelper. threadstart ()
Innerexception:
Code:
Using system; using system. collections. generic; using system. componentmodel; using system. data; using system. drawing; using system. LINQ; using system. text; using system. windows. forms; using system. data. SQLite; namespace usesqlite {public partial class form1: FORM {private string datasource = "usesqlite. SQLite "; // Private string datasource =" E:/source/PC/sqlitedb. DB "; Public form1 () {initializecomponent (); createsqlitedatabase ();} void createsqlitedatabase () {system. diagnostics. debug. writeline ("use SQLite: Start create database... "); sqliteconnection. createfile (datasource); // sqliteconnection conn = new sqliteconnection (); // sqliteconnectionstringbuilder connstr = new sqliteconnectionstringbuilder (); // connstr. datasource = datasource; // connstr. password = "admin"; // set the password, SQLite ADO. net implements Database Password protection // Conn. connectionstring = connstr. tostring (); // Conn. open (); system. diagnostics. debug. writeline ("use SQLite: Create Database End. ");}}}
Csdn user reply may be due to the following reasons:
It may be that the Framework configuration is incorrect. SQLite is. Net 4.0, and your console is. Net 4.0 client profile;
. Net 4.0 is greater than. Net 4.0 client profile to view project properties. try to change it.
. Net 4.0 client profile takes less space than. Net 4.0, but supports less types than. Net 4.0.
The dynamic library of SQLite is not supported by. Net 4.0 client profile.
Not verified.
(2) downloaded: SQLite-1.0.66.0-setup.exe, installed in vs2010 menu "Add new data source" "New Connection..." finally found the SQLite option.
Then, modify the target framework of the project from 4.0 to 3.5. Otherwise, an error is reported during compilation.
Finally, add reference in the project and select system. Data. SQLite. dll and system. Data. SQLite. dll in the \ SQLite. Net \ bin directory (optional)
(3) create a database
......