Solved

There is already an object named 'MyTable' in the database.

Posted on 2013-01-16
8
801 Views
Last Modified: 2013-01-17
Hello All;
(Classic ASP - SQL Server 2005)

I am making up a code that does the following
#1: Creates Database
#2: Creates Tables.

OK, the database part works great.
The Table part, gives me the Subject Title Error:

Microsoft OLE DB Provider for SQL Server error '80040e14'
There is already an object named 'MyTable' in the database.
/Populate.asp, line 25

This is my full code that I am using.
Can someone please let me know what is needed to make this work?
Thank You
Carrzkiss

<%
 set conn = CreateObject("ADODB.Connection") 
    conn.open "Provider=SQLOLEDB;Data Source=server-name;User ID=myUN;Password=********;" 
    sql = "CREATE DATABASE MyDatabase"
    conn.execute sql, , 129 

	   if not tableExists then 
		tableCreate = "CREATE TABLE Mytable(" & _ 
            "IDColumn INT not null," & _ 
            "IntegerColumn INT," & _ 
            "VarcharColumn VARCHAR(50)," & _ 
            "MemoColumn VarChar(MAX))" 
        conn.execute tableCreate, , 129 
    end if 
    conn.close 
    set conn = nothing 
%>

Open in new window

0
Comment
Question by:Wayne Barron
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 31

Author Comment

by:Wayne Barron
ID: 38785463
It is putting the table into Memory, NOT in the Database.
Can someone please, please let me know what the heck is going on?

Please, Anyone!
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38785988
the issue is that after you created the database, you have to "use" that database, otherwise the "create table" will go to the default (mysql) database.

so, either you reconnect after the "create database" with the created database name in teh connection string, or you do:

CREATE TABLE MyDatabase.Mytable( ...
0
 
LVL 31

Author Comment

by:Wayne Barron
ID: 38786313
Hey Angel.
Hope you are doing well.

I just added the Database name to the script as you suggested.
However, it is not creating the Table in the Database.

Is the code I have accurate for performing this procedure?

(New Code with MyDatebase.MyTable
 set conn = CreateObject("ADODB.Connection") 
    conn.open "Provider=SQLOLEDB;Data Source=server-name;User ID=myUN;Password=********;" 
    sql = "CREATE DATABASE MyDatabase"
    conn.execute sql, , 129 

	   if not tableExists then 
		tableCreate = "CREATE TABLE MyDatabase.Mytable(" & _ 
            "IDColumn INT not null," & _ 
            "IntegerColumn INT," & _ 
            "VarcharColumn VARCHAR(50)," & _ 
            "MemoColumn VarChar(MAX))" 
        conn.execute tableCreate, , 129 
    end if 
    conn.close 
    set conn = nothing 

Open in new window


Carrzkiss
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38786336
>However, it is not creating the Table in the Database.
errors?

>if not tableExists then
does this function eventually still return true due to checking the table name in the "current" (mysql) database instead of MyDatabase ?
0
 
LVL 31

Author Comment

by:Wayne Barron
ID: 38786358
No errors.
I have a response.write
Letting me know that it is completed making the database, and making the table.
Both Write out, so i know that the work is done.

I then go into SQL Server Management Studio, and see the Database "MyDatabase"
But "No" Tables have been created.

So, the next thing that I did, was to change up the code a little, into the following.

Conn.execute "CREATE TABLE MyDatabase.Mytable"

Now, I believe that something is actually starting to happen.
I get the following error.


Microsoft OLE DB Provider for SQL Server error '80040e14'
The specified schema name "OneDB" either does not exist or you do not have permission to use it.
/Populate.asp, line 41

I did some checking, and found out that I needed to give permission rights to my user.
However, I do not know how to do that part.

--
And to answer your question.
When the table is first created in (mysql), it it there.
As when I run the code again, it does me that it already exist.
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 38786383
>CREATE TABLE MyDatabase.Mytable
must then them:
CREATE TABLE MyDatabase.dbo.Mytable
0
 
LVL 43

Expert Comment

by:Eugene Z
ID: 38786459
and also in your function tableExists check  MyDatabase.dbo.Mytable (or MyDatabase.<shema>.Mytable
0
 
LVL 31

Author Closing Comment

by:Wayne Barron
ID: 38786460
Cannot believe it was something so blasted simple.
You rock Angel.
Keep up your wonderful work.

Carrzkiss
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question