使用 ADO.NET 创建新数据库 (.mdb)

发布于 2024-07-10 02:06:17 字数 48 浏览 4 评论 0原文

如何创建空的 .mdb 文件? 我正在使用 ADO.NET 和 C#。 谢谢!

How can I create a empty .mdb file? I'm using ADO.NET and C#. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

耶耶耶 2024-07-17 02:06:17

我认为没有“.NET 本机”方法可以做到这一点,但您仍然可以包装 ADOX:

using ADOX;  // add a COM reference to "Microsoft ADO Ext. x.x for DDL and Security" 

static void CreateMdb(string fileNameWithPath)
{
  ADOX.Catalog cat = new ADOX.Catalog();
  string connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Jet OLEDB:Engine Type=5";
  cat.Create(String.Format(connstr, fileNameWithPath));
  cat = null;
}

I don't think there is a ".NET native" way to do it, but you still can wrap ADOX:

using ADOX;  // add a COM reference to "Microsoft ADO Ext. x.x for DDL and Security" 

static void CreateMdb(string fileNameWithPath)
{
  ADOX.Catalog cat = new ADOX.Catalog();
  string connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Jet OLEDB:Engine Type=5";
  cat.Create(String.Format(connstr, fileNameWithPath));
  cat = null;
}
落叶缤纷 2024-07-17 02:06:17

复制预先存在的 .mdb 文件是最好的方法。

对于 ADO.NET 可以连接的大多数其他基于文件的数据库格式(例如 Excel 文件)也是如此。 由于基于文件的数据库系统使用文件系统作为其主机和 API 来与外界通信(而不是使用 TCP-IP 进行通信的 MSSQL),因此使用 System.IO 进行 MS- 等操作是很自然的SQL 将使用 T-SQL 或系统存储过程或针对这些过程的数据特定 API(例如 SQL Server 中的 SMO)来完成。

COPY model.mdb newdb.mdb 是创建 DB 命令

DEL newdb.mdb 是 drop DB 命令等。

Copy a pre-existing .mdb file is the best way.

The same is true for most of the other filebased database formats that ADO.NET can connect to, such as Excel files. Since a file based database system is using the filesystem as it's host and API for communication with the outside world (as opposed to say MSSQL which communicates using TCP-IP), it quite natural to use System.IO for actions that in say MS-SQL would be done with T-SQL or system stored procedures or a data specific API that targets thoses (say SMO in SQL server's case).

COPY model.mdb newdb.mdb is the create DB command

DEL newdb.mdb is the drop DB command, etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文