Solved

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

Posted on 2013-01-16
8
790 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
  • 4
  • 3
8 Comments
 
LVL 30

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 142

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 30

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
 
LVL 142

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 30

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 142

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 42

Expert Comment

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

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now