EDN Admin
Well-known member
Hi,
Im hoping someone can help me with this, as it is driving me crazy! I have set all the references and used the Imports statements in my code, but for some reason, when the following code is run, I get a database with no tables! I know I could do this using ADO.NET, but I am porting an app that Id originally written in VB.Net, and given the number of tables and the number of rows in each, this is one wheel Id just prefer not to reinvent, lol!
Heres the code:
Public Sub CreateDB()
sConnection = sConnection & DBPath & IDPass & ";Jet OLEDB:Engine Type=5;"
cat = New ADOX.Catalog()
cat.Create(sConnection)
con = New ADODB.Connection
With con
.Provider = "Microsoft.Jet.OLEDB.4.0;"
.CursorLocation = CursorLocationEnum.adUseClient
.Mode = ConnectModeEnum.adModeReadWrite
.ConnectionString = sConnection
.Open()
End With
cat.ActiveConnection = con
table = New ADOX.Table
With table
.Name = "User_Profiles"
.ParentCatalog = cat
column = New ADOX.Column
With column
.Name = "User_Name" 0
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Password_Protection_Enabled" 1
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adBoolean
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "TattleTale_Enabled" 2
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adBoolean
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "User_Password" 3
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Security_Question" 4
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Security_Answer" 5
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Email_Address" 6
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Mobile_Phone_Number" 7
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Mobile_Service_Provider" 8
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Mobile_SMS_Server" 9
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Mobile_MMS_Server" 10
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Email_Enabled" 11
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adBoolean
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "SMS_Enabled" 12
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adBoolean
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "MMS_Enabled" 13
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adBoolean
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Default_Wallpaper" 14
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Document_Background_Color" 15
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Document_Font_Color" 16
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Default_Font" 17
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Default_Font_Size" 18
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Document_Left_Margin" 19
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Document_Right_Margin" 20
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Is_Default_Profile" 21
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adBoolean
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Toolbar_Visible" 22
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adBoolean
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Options_Toolbar_Visible" 23
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adBoolean
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Status_Bar_Visible" 24
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adBoolean
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Timestamp_Entries" 25
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adBoolean
End With
.Columns("User_Password").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("Security_Question").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("Security_Answer").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("Email_Address").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("Mobile_Phone_Number").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("Mobile_Service_Provider").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("Mobile_SMS_Server").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("Mobile_MMS_Server").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("Default_Wallpaper").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("Document_Background_Color").Properties("Jet OledB:Allow Zero Length").Value = True
.Columns("Document_Font_Color").Properties("Jet Oledb: Allow Zero Length").Value = True
.Columns("Default_Font").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("Document_Left_Margin").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("Document_Right_Margin").Properties("Jet Oledb:Allow Zero Length").Value = True
End With
cat.Tables.Append(table)
table = New ADOX.Table
With table
.Name = "User_Files"
.ParentCatalog = cat
column = New ADOX.Column
With column
.Name = "File_Name" 0
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Path_To_File" 1
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Date_Created" 2
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Date_Last_Modified" 3
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "File_Size" 4
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "File_Content" 5
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "File_Author" 6
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "File_Password_Enabled" 7
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "File_Password" 8
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
.Columns("File_Name").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("Path_To_File").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("Date_Created").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("Date_Last_Modified").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("File_Size").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("File_Content").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("File_Author").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("File_Password").Properties("Jet Oledb:Allow Zero Length").Value = True
End With
cat.Tables.Append(table)
con.Close()
con = Nothing
table = Nothing
cat = Nothing
End Sub
View the full article
Im hoping someone can help me with this, as it is driving me crazy! I have set all the references and used the Imports statements in my code, but for some reason, when the following code is run, I get a database with no tables! I know I could do this using ADO.NET, but I am porting an app that Id originally written in VB.Net, and given the number of tables and the number of rows in each, this is one wheel Id just prefer not to reinvent, lol!
Heres the code:
Public Sub CreateDB()
sConnection = sConnection & DBPath & IDPass & ";Jet OLEDB:Engine Type=5;"
cat = New ADOX.Catalog()
cat.Create(sConnection)
con = New ADODB.Connection
With con
.Provider = "Microsoft.Jet.OLEDB.4.0;"
.CursorLocation = CursorLocationEnum.adUseClient
.Mode = ConnectModeEnum.adModeReadWrite
.ConnectionString = sConnection
.Open()
End With
cat.ActiveConnection = con
table = New ADOX.Table
With table
.Name = "User_Profiles"
.ParentCatalog = cat
column = New ADOX.Column
With column
.Name = "User_Name" 0
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Password_Protection_Enabled" 1
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adBoolean
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "TattleTale_Enabled" 2
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adBoolean
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "User_Password" 3
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Security_Question" 4
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Security_Answer" 5
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Email_Address" 6
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Mobile_Phone_Number" 7
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Mobile_Service_Provider" 8
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Mobile_SMS_Server" 9
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Mobile_MMS_Server" 10
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Email_Enabled" 11
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adBoolean
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "SMS_Enabled" 12
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adBoolean
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "MMS_Enabled" 13
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adBoolean
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Default_Wallpaper" 14
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Document_Background_Color" 15
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Document_Font_Color" 16
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Default_Font" 17
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Default_Font_Size" 18
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Document_Left_Margin" 19
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Document_Right_Margin" 20
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Is_Default_Profile" 21
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adBoolean
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Toolbar_Visible" 22
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adBoolean
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Options_Toolbar_Visible" 23
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adBoolean
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Status_Bar_Visible" 24
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adBoolean
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Timestamp_Entries" 25
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adBoolean
End With
.Columns("User_Password").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("Security_Question").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("Security_Answer").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("Email_Address").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("Mobile_Phone_Number").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("Mobile_Service_Provider").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("Mobile_SMS_Server").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("Mobile_MMS_Server").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("Default_Wallpaper").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("Document_Background_Color").Properties("Jet OledB:Allow Zero Length").Value = True
.Columns("Document_Font_Color").Properties("Jet Oledb: Allow Zero Length").Value = True
.Columns("Default_Font").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("Document_Left_Margin").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("Document_Right_Margin").Properties("Jet Oledb:Allow Zero Length").Value = True
End With
cat.Tables.Append(table)
table = New ADOX.Table
With table
.Name = "User_Files"
.ParentCatalog = cat
column = New ADOX.Column
With column
.Name = "File_Name" 0
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Path_To_File" 1
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Date_Created" 2
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "Date_Last_Modified" 3
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "File_Size" 4
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "File_Content" 5
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "File_Author" 6
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "File_Password_Enabled" 7
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
column = New ADOX.Column
With column
.Name = "File_Password" 8
.ParentCatalog = cat
.Attributes = ColumnAttributesEnum.adColNullable
.Type = ADOX.DataTypeEnum.adVarWChar
End With
.Columns.Append(column)
.Columns("File_Name").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("Path_To_File").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("Date_Created").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("Date_Last_Modified").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("File_Size").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("File_Content").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("File_Author").Properties("Jet Oledb:Allow Zero Length").Value = True
.Columns("File_Password").Properties("Jet Oledb:Allow Zero Length").Value = True
End With
cat.Tables.Append(table)
con.Close()
con = Nothing
table = Nothing
cat = Nothing
End Sub
View the full article