示例#1
0
        /// <summary>
        /// Creates an Access 2003 database. If the filename specified exists it is
        /// overwritten.
        /// </summary>
        /// <param name="fileName">The name of the databse to create.</param>
        /// <param name="version">The version of the database to create.</param>
        public static void CreateMDB(string fileName, AccessDbVersion version = AccessDbVersion.Access2003)
        {
            ;
            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            string command = "";

            switch (version)
            {
            case AccessDbVersion.Access95:
                command = "CREATE_DBV3";
                break;

            case AccessDbVersion.Access2000:
                command = "CREATE_DBV4";
                break;

            case AccessDbVersion.Access2003:
                command = "CREATE_DB";
                break;
            }

            string attributes = String.Format("{0}=\"{1}\" General\0", command, fileName);
            int    retCode    = SQLConfigDataSource
                                    (0, ODBC_Constants.ODBC_ADD_DSN,
                                    GetOdbcProviderName(), attributes);

            if (retCode == 0)
            {
                int errorCode       = 0;
                int resizeErrorMesg = 0;
                var sbError         = new StringBuilder(512);
                SQLInstallerError(1, ref errorCode, sbError, sbError.MaxCapacity, ref resizeErrorMesg);
                throw new ApplicationException(string.Format("Cannot create file: {0}. Error: {1}", fileName, sbError));
            }
        }
示例#2
0
        /// <summary>
        /// Creates an Access 2003 database. If the filename specified exists it is 
        /// overwritten.
        /// </summary>
        /// <param name="fileName">The name of the databse to create.</param>
        /// <param name="version">The version of the database to create.</param>
        public static void CreateMDB(string fileName, AccessDbVersion version = AccessDbVersion.Access2003)
        {
            ;
            if (File.Exists(fileName)) {
                File.Delete(fileName);
            }

            string command = "";
            switch (version)
            {
                case AccessDbVersion.Access95:
                    command = "CREATE_DBV3";
                    break;
                case AccessDbVersion.Access2000:
                    command = "CREATE_DBV4";
                    break;
                case AccessDbVersion.Access2003:
                    command = "CREATE_DB";
                    break;
            }

            string attributes = String.Format("{0}=\"{1}\" General\0", command, fileName);
            int retCode = SQLConfigDataSource
                (0, ODBC_Constants.ODBC_ADD_DSN,
                 GetOdbcProviderName(), attributes);
            if (retCode == 0)
            {
                int errorCode = 0 ;
                int  resizeErrorMesg = 0 ;
                var sbError = new StringBuilder(512);
                SQLInstallerError(1, ref errorCode, sbError, sbError.MaxCapacity, ref resizeErrorMesg);
                throw new ApplicationException(string.Format("Cannot create file: {0}. Error: {1}", fileName, sbError));
            }
        }