SQLite和Linq错误:没有这样的表

时间:2013-02-04 20:20:51

标签: c# winforms sqlite dblinq

我使用这两个命令使用DBLinq在C#/ winform中创建了一个Linq和SQLite应用程序:

DbMetal /provider:Sqlite /conn "Data Source=path\to\database.s3db" /dbml:path\to\Database.dbml

DbMetal /code:path\to\DatabaseContext.cs path\to\Database.dbml

获取与数据库的连接:

string dataSource = @"Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "database.s3db";
var connection = new SQLiteConnection(dataSource);
Main db = new Main(connection, new SqliteVendor());

查询数据库:

var user = db.User.SingleOrDefault(u => u.UserName == username);

运行这行代码,我得到No shuch table异常:

no such table: main.USER
System.Data.SQLite.SQLiteException was unhandled HResult=-2147467259 Message=SQLite error
no such table: main.USER
Source=System.Data.SQLite 
ErrorCode=-2147467259
StackTrace:
    at System.Data.SQLite.SQLite3.Prepare(SQLiteConnection cnn, String strSql, SQLiteStatement previous, UInt32 timeoutMS, String& strRemain)
    at System.Data.SQLite.SQLiteCommand.BuildNextCommand()        
    at System.Data.SQLite.SQLiteCommand.GetStatement(Int32 index)
    at System.Data.SQLite.SQLiteDataReader.NextResult()
    at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
    at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
    at System.Data.SQLite.SQLiteCommand.ExecuteDbDataReader(CommandBehavior behavior)
    at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
    at DbLinq.Data.Linq.Sugar.Implementation.QueryRunner.Select[T](SelectQuery selectQuery)
    at DbLinq.Data.Linq.Sugar.Implementation.QueryRunner.SelectSingle[S](SelectQuery selectQuery, Boolean allowDefault)
    at DbLinq.Data.Linq.Sugar.Implementation.QueryRunner.SelectScalar[S](SelectQuery selectQuery)
    at DbLinq.Data.Linq.Implementation.QueryProvider`1.Execute[TResult](Expression expression)
    at System.Linq.Queryable.SingleOrDefault[TSource](IQueryable`1 source, Expression`1 predicate)
...

数据库文件存在,我有表。 有什么想法吗?

0 个答案:

没有答案