SQLite文件的打开问题

meceky 2010-06-29 03:48:46
Main:

//
public static void CreateDb()
{
string dbPath = @"e:\DataBase\Demo.db3";
if (!File.Exists(dbPath))
{
File.Create(dbPath);
}
SQLiteHelper.CreatTable(dbPath);
}
// Create Table
public static void CreatTable(string dbFile)
{
using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + dbFile))
{
connection.Open();
using (SQLiteCommand command = new SQLiteCommand(connection))
{
command.CommandText = "Create Table Demo(id integer not null primary key autoincrement unique)";
command.ExecuteNonQuery();
}
}

程序运行的时候提示connection.opne()无法代开文件。不小的是为什么?
...全文
469 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
meceky 2010-06-29
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 meceky 的回复:]

引用 3 楼 ledmhcc 的回复:

创建时File对象没关闭,进程锁死了才打不开的吧

这个要好好研究!!
[/Quote]
刚开始学SQLite,有些方法还不熟悉!
meceky 2010-06-29
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 ledmhcc 的回复:]

创建时File对象没关闭,进程锁死了才打不开的吧
[/Quote]
这个要好好研究!!
ddccqq123 2010-06-29
  • 打赏
  • 举报
回复

System.Data.SQLite.SQLiteConnection.CreateFile(filePath)

//其中filePath是物理路径+文件名,并且所在文件夹必须存在。

你为什么要自己创建文件呢~~当然用人家自带的啦~~
ledmhcc 2010-06-29
  • 打赏
  • 举报
回复
创建时File对象没关闭,进程锁死了才打不开的吧
meceky 2010-06-29
  • 打赏
  • 举报
回复
第一次创建文件,当时创建成功后提示打开失败。
此时文件已经存在,第二次运行此代码却没有问题。
mayonglong 2010-06-29
  • 打赏
  • 举报
回复
Demo.db3,怎么能直接File.Create出来呢~

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧