Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Table in correct SQL database

Status
Not open for further replies.

BMarkham

Programmer
Apr 30, 2001
14
US
I'm using ADO from VBA to send a CreateTable statment to a SQL server. My connection string looks like this:

"Provider=SQLOLEDB;Server=ServerName;Intitial Catalog=DatabaseName;Integrated Security=SSPI"

I create a command object that uses the above connection string. I set the command object's commandText property to my CreateTable statement. When I execute my make table statement, the table is created in the Master database and not the one specified by my connection string (DatabaseName). I've gotten around this by executing a "USE DatabaseName" statment through my command object before I execute the CreateTable.

My question is. Is there a better way? Am I missing something, or is this how I have to do it?

Thanks
 
I believe you can specify the database, owner, and table name in the same 'Create' statement :

strSQL = &quot;CREATE TABLE <db>.<owner>.tablename ...




Mark


A molehill man is a pseudo-busy executive who comes to work at 9 AM and finds a molehill on his desk. He has until 5 PM to make this molehill into a mountain. An accomplished molehill man will often have his mountain finished before lunch
- Fred Allen
 
Thanks for the reply Mark, but after much wasted time and hair pulling, I realized I had a typo in the connection string.

Actually, if you look above, I spelled &quot;Initial Catalog&quot; with an extra 't' after the 'n'.

Duhhhh!

Brett
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top