Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem adding Column Default using DMO in SQL 2005

Status
Not open for further replies.

bernardmanning

Programmer
Oct 14, 2003
61
GB
Hi

I wonder if anybody could help me out here ;

I have a routine which works fine under SQL server 2000, but when I run it aganst a newly installed version of SQL server 2005 Developers Edition Beta 2 I get a problem when I attempt to add a column default.

Here's the code

oSQLServer = CREATEOBJECT("SQLDMO.SQLServer")
oSQLServer.Connect(".","userid","password")

dmoDatabase = CreateObject("SQLDMO.Database2")
dmoDBFile = CreateObject("SQLDMO.DBFile")
dmoLogFile = CreateObject("SQLDMO.LogFile")

dmoDatabase.NAME = "Test DataBase"
dmoDatabase.collation = "SQL_Latin1_General_CP1_CI_AS"

dmoDBFile.NAME = "Test DataBase"
dmoDBFile.PhysicalName = "C:\TEST.mdf"
dmoDBFile.PrimaryFile = .T.
dmoDatabase.FileGroups("PRIMARY").DBFiles.ADD(dmoDBFile)

dmoLogFile.Name = "TEST.log"
dmoLogFile.PhysicalName = "C:\TEST.ldf"
dmoDatabase.TransactionLog.LogFiles.ADD(dmoLogFile)

oSQLServer.DATABASES.ADD(dmoDatabase)

* now add the default

dmoDefault = CreateObject("SQLDMO.Default")
dmoDefault.Name = 'UW_ZeroDefault'
dmoDefault.Text = '0'
dmoDatabase.Defaults.Add(dmoDefault) && error occurs here!
dmoDefault = .F.

when the code reaches the ADD(DmoDefault) line it errors out with a :

OLE IDispatch exception code 207 from Microsoft SQL-DMO (ODBC SQLState 42s22)

"Invalid Column name 'id'."

Has anybody got any ideas what this could be, again this works fine under sql server 2000.

Thanks, Bernard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top