Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I am creating a database through VB.NET code from a database level user and i want to create a table to it...I am getting exception as

 " There is already an object named 'xHawk' in the database.<br />
Cannot find the user 'test', because it does not exist or you do not have permission."


xHawk is the database i created..thanks in advance....please help me out...

Here is the query i wrote...
VB
Dim strTable As String = "GRANT CREATE TABLE TO test  CREATE TABLE xHawk(StudentId INTEGER CONSTRAINT PkeyMyId PRIMARY KEY," + "Name CHAR(50)," + "Address CHAR(255)," + "Contact INTEGER);"
Posted
Updated 27-Mar-12 0:36am
v4
Comments
sachin10d 27-Mar-12 7:30am    
you are having a xHawk database and your creating a table named xHawk in that database
is it right?

Hi,

It seems you are trying to create an already existing table, hence the "There is already an object named xHawk in the database".

Try using something like this, beware it will delete you table before creating it again:

SQL
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[xHawk]') AND type = N'U')
DROP TABLE [dbo].[xHawk]


Notice the [dbo], it is recommended to use schemas but if you don't, just remove "[dbo]".

Hope it helps.
 
Share this answer
 
Comments
DileepkumarReddy 27-Mar-12 6:34am    
'xHawk' Database is empty...i think that exception is related to permissions..
what _Zorro_ says is right
you will have to use this
SQL
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[xHawk]') AND type = N'U')
DROP TABLE [dbo].[xHawk]
go

GRANT CREATE TABLE TO test  CREATE TABLE xHawk(StudentId INTEGER CONSTRAINT PkeyMyId PRIMARY KEY,Name CHAR(50),Address CHAR(255),Contact INTEGER)

If the execption is related permission it gives the following error.
HTML
Cannot grant, deny, or revoke permissions to sa, dbo, entity owner, information_schema, sys, or yourself.
The specified schema name "dbo" either does not exist or you do not have permission to use it.
 
Share this answer
 
v2
Comments
DileepkumarReddy 27-Mar-12 7:40am    
Dim strTable As String = "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[xHawk]') AND type = N'U') " & _
"DROP TABLE [dbo].[xHawk] " & _
" GO " & _
"GRANT CREATE TABLE TO test CREATE TABLE xHawk(StudentId INTEGER CONSTRAINT PkeyMyId PRIMARY KEY,Name CHAR(50),Address CHAR(255),Contact INTEGER);"


Exception: " Incorrect syntax near 'GO'"...please help me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900