?
Solved

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

Posted on 2013-01-16
8
Medium Priority
?
804 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

800 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