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
Solved

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

Posted on 2013-01-16
8
795 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 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 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
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 insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

856 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