Create new DB in code

  • Thread starter Thread starter joejohnsonwall
  • Start date Start date
J

joejohnsonwall

When opening a connection object, the connection string must name a
Database file that already exists to open. If I want to create a new
database file that does not already exist, how do I code ADO.NET to
create and open the connection object so I can issue an SQL "CREATE
DATABASE" non-query command to create the new file ? (Language:C#,
C++, or VB)
 
Hi Joe,

What kind of database, you can create an Access database using ADO, however
tell first what database. Because the fact that you are talking about a file
I think it is Access however I am not sure of that.

Cor
"
When opening a connection object, the connection string must name a
 
On 21 Jul 2004 06:03:26 -0500, (e-mail address removed)-spam.invalid (joejohnsonwall)
wrote:

¤ When opening a connection object, the connection string must name a
¤ Database file that already exists to open. If I want to create a new
¤ database file that does not already exist, how do I code ADO.NET to
¤ create and open the connection object so I can issue an SQL "CREATE
¤ DATABASE" non-query command to create the new file ? (Language:C#,
¤ C++, or VB)

What kind of database?


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Initially it will be Access as all the computers on our network have
Access. We have a server with SQL2000 as required by a product our
facility bought, then dumped after 1 1/2 years. I approached our
system folks about being granted access to that server so I could use
that system and develop my skills, but was turned down. My thoughts
at this point are to develop an Access system which will serve well
to develop my ADO.NET skills. Once I can show a usable, helpful
system using Access to my superiors, I expect I will be in a position
to have them talk to the system folks about the SQL server with
SQL2000.
Anyway, my plan is that on start-up, the system will check the
registry for the location of the database. If there is no registry
entry, or if the file does not exist where it is supposed to be, the
program should offer the user the option of creating the database.
 
Hi Joe,

Telling that it is access is enough. :-)

set a reference to COM adox ext 2.x for dll and security
\\\
Dim catNewDB As New ADOX.Catalog
catNewDB.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data
Source=C:\db1.mdb")
///
I hope this helps a little bit?

Cor

....
 
On 21 Jul 2004 09:06:52 -0500, (e-mail address removed)-spam.invalid (joejohnsonwall)
wrote:

¤ Initially it will be Access as all the computers on our network have
¤ Access. We have a server with SQL2000 as required by a product our
¤ facility bought, then dumped after 1 1/2 years. I approached our
¤ system folks about being granted access to that server so I could use
¤ that system and develop my skills, but was turned down. My thoughts
¤ at this point are to develop an Access system which will serve well
¤ to develop my ADO.NET skills. Once I can show a usable, helpful
¤ system using Access to my superiors, I expect I will be in a position
¤ to have them talk to the system folks about the SQL server with
¤ SQL2000.
¤ Anyway, my plan is that on start-up, the system will check the
¤ registry for the location of the database. If there is no registry
¤ entry, or if the file does not exist where it is supposed to be, the
¤ program should offer the user the option of creating the database.

For Access you still need to use COM ADOX (Microsoft ADO Ext 2.0 for DDL and Security) to create the
database. You can use Access DDL or ADOX to create Tables:

Dim tbl As New ADOX.Table
Dim col As New ADOX.Column
Dim cat As New ADOX.Catalog

'Engine Type=4 is Access 97 and a value of 5 is Access 2000
cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=e:\My Documents\db13.mdb;" & _
"Jet OLEDB:Engine Type=4;")

tbl.Name = "NewTable"
col.Name = "AutoField"
col.Type = ADOX.DataTypeEnum.adInteger
col.ParentCatalog = cat
col.Properties("AutoIncrement").Value = True
tbl.Columns.Append(col)
col = New ADOX.Column
col.Name = "DateField"
col.Type = ADOX.DataTypeEnum.adDate
tbl.Columns.Append(col)
col = New ADOX.Column
col.Name = "Address2"
col.Type = ADOX.DataTypeEnum.adVarWChar
col.DefinedSize = 20
col.Attributes = ADOX.ColumnAttributesEnum.adColNullable
tbl.Columns.Append(col)
col = New ADOX.Column
col.Name = "Age"
col.Type = ADOX.DataTypeEnum.adInteger
col.Attributes = ADOX.ColumnAttributesEnum.adColNullable
tbl.Columns.Append(col)
cat.Tables.Append(tbl)

cat.Tables("NewTable").Columns("Address2").Properties("Jet OLEDB:Allow Zero Length").Value =
True

cat.ActiveConnection.Close()


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Thank you. If I can not directly do it with ADO.NET, I will fall back
on MFC for database creation. I am surprised ADO.NET has such a
glaring hole.

Thank you again.
 
Back
Top