2015-05-28 53 views
0

我想從C#應用程序(VS2010 Pro)連接並從android(sqlite)數據庫中讀取數據。我已經嘗試了不同版本的System.Data.SQLite.dll(對於.NET 3.5,在x64上的x86/.NET 4.0上)。 不過我不能去了這個異常:從C#打開Android數據庫:「目前僅支持SQLite版本3」NotSupportedException

*System.NotSupportedException was unhandled 
HResult=-2146233067 
Message=Only SQLite Version 3 is supported at this time 
Source=System.Data.SQLite 
StackTrace: 
    at System.Data.SQLite.SQLiteConnection.Open() 
    at ConsoleApplication1.Program.Main(String[] args) in C:\Users\lucian.teodorescu\documents\visual studio 2010\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs:line 18 
    at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
    at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) 
    at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 
    at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
    at System.Threading.ThreadHelper.ThreadStart() 

的InnerException:*

我的代碼是:

using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Text; 
    using System.Data.SQLite; 
    using System.Data; 

    namespace ConsoleApplication1 
    { 
    class Program 
    { 
     static void Main(string[] args) 
     { 
     SQLiteConnection m_dbConnection; 
     m_dbConnection = new SQLiteConnection("Data Source=\\\\192.xxx.xx.xxx:5555\\data\\data\\MyApp\\sqlite_db\\AUTOMATICTEST\\W1579_W2PR_QA_R13.db;Version=0;"); 
     //m_dbConnection = new SQLiteConnection("Data Source=L:\\Lucian\\workspace\\W1579_W2PR_QA_R13.db;Version=0;"); 
     m_dbConnection.Open(); 
     string sql = "select * from SSS_CUSTOMER WHERE customer_number01 = 90685"; 
     SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection); 
     Console.WriteLine(sql); 
     } 
    } 
    } 

展望this源,上線823,我覺得這一點,但我仍然沒有得到它:

if (Convert.ToInt32(FindKey(opts, "Version", "3"), CultureInfo.InvariantCulture) != 3) 
    throw new NotSupportedException("Only SQLite Version 3 is supported at this time"); 

需要做些什麼來克服是例外嗎?

+0

什麼,如果通過3字符串的末尾替換0:'m_dbConnection =新SQLiteConnection(「數據源= \\\\ 192.xxx.xx.xxx:5555\\data \\ data \\ MyApp \\ sqlite_db \\ AUTOMATICTEST \\ W1579_W2PR_QA_R13.db; Version = 0;「);' – anil

+0

@anil brilliant!我運行了一個adb命令來查看我的db版本,它返回0.看來我沒有得到參數的正確角色!謝謝! – Lucian

+0

您可以將其作爲答案發布 – Lucian

回答

0

連接字符串中的版本= 3已解決問題。新的連接字符串是:

m_dbConnection = new SQLiteConnection("Data Source=\\\\192.xxx.xx.xxx:5555\\data\\data\\MyApp\\sqlite_db\\AUTOMATICTEST\\W1579_W2PR_Q‌​A_R13.db;Version=3;");