Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Other SQL Server 2008 Topics
 Error creating column

Author  Topic 

Squiffy
Starting Member

8 Posts

Posted - 2009-02-25 : 02:43:16
VS VB 2008
SQL server 2008

Im trying to create a column in a table. I have been able to drop and rename columns but can not create. Can anyone see whats wrong with the code.

I'm getting the error 'Create failed for Table 'dbo.employees' on tb.create()

Thanks in advance.

Imports Microsoft.SqlServer.Management.Smo
Imports Microsoft.SqlServer.Management.Common

Function AddSQLColumn(ByVal Name As String) As Boolean

Dim svr As New Server(SERVER_NAME)
svr.ConnectionContext.LoginSecure = False
svr.ConnectionContext.Login = DB_USER
svr.ConnectionContext.DatabaseName = DATABASE_NAME
svr.ConnectionContext.Password = DB_PASSWORD
svr.ConnectionContext.Connect()
Dim db As Database = svr.Databases(DATABASE_NAME)
Dim tb As New Table(db, "employees")
Dim col As New Column(tb, Name, DataType.Int)
col.Nullable = True
col.Default = "0"
tb.Columns.Add(col)
tb.Create()
End Function

heavymind
Posting Yak Master

115 Posts

Posted - 2009-02-26 : 05:26:51
are you able to add this column using pure t-sql?

Thanks, Vadym
MCITP DBA 2005/2008
Chief DBA at http://www.db-staff.com
Go to Top of Page

Squiffy
Starting Member

8 Posts

Posted - 2009-02-26 : 07:42:32
Hi Vadym

I have no problem using TSQL using an execute command and due to pure frustration this is what I am using now.

But I wanted to migrate to SMO and this is very frustrating. No one else has this problem as far as I can Google.

I need to ship the demo over the next few days so I think I'm stuck with TSQL.

Thanks Vadym
Go to Top of Page

heavymind
Posting Yak Master

115 Posts

Posted - 2009-02-26 : 08:22:03
try also to catch the statement generated by SMO in profiler. But I doubt if it makes it into sql server. Probably it fails earlier inside the SMO.

Thanks, Vadym
MCITP DBA 2005/2008
Chief DBA at http://www.db-staff.com
Go to Top of Page
   

- Advertisement -