You must use C # To dynamically create an Access database.
Office 2007 is used, and the database file format is. accdb
At the beginning, I thought I would check whether the file exists. If it does not exist, I would just create a database file.
The Code is as follows:
String filepath = new directoryinfo ("."). fullname + @ "\ data. accdb"; if (! File. exists (filepath) {console. writeline ("file data. accdb does not exist "); filestream FS = file. create (filepath); FS. close (); string connstr = string. format ("provider = Microsoft. ace. oledb.12.0; Data Source = {0} ", filepath); oledbconnection conn = new oledbconnection (connstr); Conn. open (); oledbcommand created STR = new oledbcommand (); created Str. connection = conn; Response Str. commandtext = "create table usrinfo (usrid int not null primary key, usrname char (16), kgname char (16), usrsignature char (255)"; Comment Str. executenonquery ();}
When the conn. open () method is called, the following error occurs: Unrecognized database format
Error:
Check the file. The size is 0. If you create the file manually, the initial size of data. accdb is not 0.
Error cause:
When using the CREATE () method of the file class, only empty files are created, and the basic format of the Access database is not available.
Solution:
Use C # the correct method to dynamically create an Access database