[英]Create Access Database in C# using ODBC
如何使用C#和ODBC创建MS Access数据库?
Judging from this: How do I specify the ODBC Access Driver Format when creating the database 从此判断: 创建数据库时如何指定ODBC访问驱动程序格式
I'd say like this: 我会这样说:
enum RequestFlags : int
{
ODBC_ADD_DSN = 1,
ODBC_CONFIG_DSN = 2,
ODBC_REMOVE_DSN = 3,
ODBC_ADD_SYS_DSN = 4,
ODBC_CONFIG_SYS_DSN = 5,
ODBC_REMOVE_SYS_DSN = 6,
ODBC_REMOVE_DEFAULT_DSN = 7
}
[DllImport("ODBCCP32.DLL",CharSet=CharSet.Unicode, SetLastError=true)]
static extern bool SQLConfigDataSourceW(UInt32 hwndParent , RequestFlags fRequest, string lpszDriver, string lpszAttributes);
Having this in your main method: 在您的主要方法中有以下内容:
string strDriverName = "Microsoft Access Driver (*.mdb, *.accdb)";
string strAttr = "CREATE_DBV12=c:\access2007.accdb";
SQLConfigDataSource(0, RequestFlags.ODBC_ADD_DSN, strDriverName, strAttr );
Warning: Untested 警告:未经测试
Note: I copied the pInvoke info from pinvoke.net. 注意:我从pinvoke.net复制了pInvoke信息。
UInt32 hwndParent seems wrong, that should probably be UIntPtr. UInt32 hwndParent似乎是错误的,应该应该是UIntPtr。
This is especially important on Win64, which I think you need when I look at your tags. 这在Win64上尤其重要,我认为在查看标签时需要使用Win64。
If so, use UIntPtr.Zero instead of 0. But try first. 如果是这样,请使用UIntPtr.Zero而不是0。但是请首先尝试。
Also note that I wouldn't use an access database for new projects if they are intended to be large. 还要注意,如果新项目打算很大,我不会将访问数据库用于新项目。 If you need a standalone database, use Firebird embedded instead.
如果您需要独立数据库,请使用嵌入式Firebird。 That way you can save yourself a lot of trouble later.
这样一来,您以后就可以省去很多麻烦。
Also note that newer 64-bit versions of windows ship without Access-driver preinstalled AFAIK. 另请注意,出厂时没有预安装Access-driver的较新的64位Windows版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.