Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 17th, 2003, 06:16 AM
gpc gpc is offline
Authorized User
 
Join Date: Dec 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to create a new database?

The SQL for creating a new database is simple:
CREATE DATABASE dbname
But how do you execute that in ASP? I tried the obvious:

Set cmdDB = Server.CreateObject("ADODB.Command")
cmdDB.CommandText = "CREATE DATABASE dbname"
cmdDB.CommandType = adCmdText
cmdDB.Execute

And I get the error message:
Operation is not allowed on an object referencing a closed or invalid connection.

But to assign an open Connection to the Command object I have to have a file name when I open the Connection, but the file doesn't exist yet.

What am I missing? Or is this a Catch-22?
 
Old December 17th, 2003, 02:26 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

This is not a catch-22. You need to connect to a database in SQL to do stuff as you know. Obviously you cannot connect to the database you are about to connect, but you should be able to connect to "master" with an authorized user login. Then you should be able to create the new database.

As long as you have an authorized user to connect to master with you are all set.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old December 17th, 2003, 02:27 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

And what do you mean by "I have to have a file name"? What kind of file do you need? Do you mean a connection file like a UDL?

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old December 17th, 2003, 03:06 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Are you trying to create a new database in SQL Server? Or are you trying to create another database, like Microsoft Access?

Your original post mentions SQL, but that might just as well refer to T-SQL..... And the file reference makes me suspect an .MDB database.


Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old December 17th, 2003, 03:59 PM
gpc gpc is offline
Authorized User
 
Join Date: Dec 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<p>To open a connection, isn't a filename needed? The string dbname in the following:

<p>Set cnDB = Server.CreateObject("ADODB.Connection")
cnDB.Open "DBQ=" & dbname & ";ReadOnly=0;" & "DRIVER={Microsoft Access Driver (*.mdb)};"

<p>If I omit the DBQ=filename I get an error message:

<p>Drivers error '80040e4e'
<br>Operation was canceled.


<p>
Quote:
quote:Originally posted by planoie
 And what do you mean by "I have to have a file name"? What kind of file do you need? Do you mean a connection file like a UDL?

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old December 17th, 2003, 04:07 PM
gpc gpc is offline
Authorized User
 
Join Date: Dec 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks. Could you clarify what the ASP is to connect to "master"? I'm kind of groping around here, with only "Beginning ASP 3.0" and what I can find online for reference.

Quote:
quote:Originally posted by planoie
 This is not a catch-22. You need to connect to a database in SQL to do stuff as you know. Obviously you cannot connect to the database you are about to connect, but you should be able to connect to "master" with an authorized user login. Then you should be able to create the new database.

As long as you have an authorized user to connect to master with you are all set.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old December 17th, 2003, 04:13 PM
gpc gpc is offline
Authorized User
 
Join Date: Dec 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My goal is to create a new MS Access database, to which I can copy data that's in an Excel spreadsheet. There are limitations on how much I can do to the .xls spreadsheet -- eg, ALTER isn't implemented -- which I believe won't be an issue with the .mdb file.

Quote:
quote:Originally posted by Imar
 Are you trying to create a new database in SQL Server? Or are you trying to create another database, like Microsoft Access?

Your original post mentions SQL, but that might just as well refer to T-SQL..... And the file reference makes me suspect an .MDB database.


Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old December 17th, 2003, 05:19 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Right. If it's an Access database, you may want to check out this article.

It describes how to create a new Access database from code, and add a table with a couple of columns in it.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old December 17th, 2003, 07:05 PM
gpc gpc is offline
Authorized User
 
Join Date: Dec 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Excellent -- that looks like exactly what I want.

I notice that when you create the first column you set the property col.ParentCatalog = catDB, but you don't do that with the other columns. Does that property get associated with the table as a whole once it is associated with one of the table's columns?



Quote:
quote:Originally posted by Imar
 Right. If it's an Access database, you may want to check out this article.

It describes how to create a new Access database from code, and add a table with a couple of columns in it.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old December 18th, 2003, 03:14 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

In the example in the article, ParentCatalog is required for the ID column. The code uses an AutoIncrement property, and to use that successfully, ADOX needs to know what kind of database you're using (specified in the catDB).

You could also add it to the table, if you want:
Code:
' Now add the rest of the columns
With tblNew
    .ParentCatalog = catDB
    ' Create fields and append them to the
    ' Columns collection of the new Table object.
    With .Columns
    but it doesn't make a difference in this case, because no special properties are used.

Cheers,

Imar




---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i create a new ado database ? jerryham VB.NET 8 October 13th, 2008 09:21 PM
Ex0201 - Create Database khempire C# 2 January 14th, 2008 08:26 PM
Unable to create database. rupen SQL Server 2005 4 December 6th, 2007 02:39 AM
How to create a Database koushikroy2001 SQL Language 2 January 4th, 2006 04:03 AM
Create database Yee MySQL 2 November 5th, 2004 06:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.