Prev: How to find out what rows successfuly/failed to insert
Next: Visual Studio 2008 database project or just use SSMS?
From: eliza on 25 Mar 2010 08:48 SQL Server Management Objects (SMO) are objects designed for programmatic management of Microsoft SQL Server. We can integrate SMO into any .NET based applications. SMO is also compatible with SQL Server version 7.0, SQL Server 2000, and SQL Server 2005, which makes it easy to manage a multi-version environment. Following code is used to run the Microsoft SQL Server Query files(script files) kept in applications bin\Debug folder, with SMO. http://www.mindfiresolutions.com/Run-the-existing-SQL-Script-programmatically-with-SMO-526.php Lubomi wrote: Create a table with SMO 28-Aug-07 Hi, I want to create a new table in existing database programmatically with SMO. When I call Table.Create() method I get an excpetion "Create failed for table..." and an inner exception "Set property Text to acomplish this action." Neither Table, nor Column has a property Text. So what could be wrong? To find out what's going on, I created the SQL script from the table with the method Table.Script(). Than I pasted this script into Server management console and run it. There was everything OK and table was created. What can be wrong when I run Table.Create() method ? Thanks for help. Regards, Lubomir Previous Posts In This Thread: On Tuesday, August 28, 2007 4:04 PM Lubomi wrote: Create a table with SMO Hi, I want to create a new table in existing database programmatically with SMO. When I call Table.Create() method I get an excpetion "Create failed for table..." and an inner exception "Set property Text to acomplish this action." Neither Table, nor Column has a property Text. So what could be wrong? To find out what's going on, I created the SQL script from the table with the method Table.Script(). Than I pasted this script into Server management console and run it. There was everything OK and table was created. What can be wrong when I run Table.Create() method ? Thanks for help. Regards, Lubomir On Wednesday, August 29, 2007 3:49 AM Tibor Karaszi wrote: Hard to say... I created a simple example that works, see below. Hard to say... I created a simple example that works, see below. Perhaps you can compare that to your current code and see if you can spot the difference? Imports Microsoft.SqlServer.Management.Common Imports Microsoft.SqlServer.Management.Smo Module Module1 Sub Main() Dim Svr As New Server("machinename") Dim AWDBase As Database = Svr.Databases("tempdb") Dim DiscountsTable As New Table(AWDBase, "Discounts") Dim DiscountID As New Column(DiscountsTable, "DiscountID", DataType.Int) Dim DiscountName As New Column(DiscountsTable, "DiscountName", DataType.NVarChar(40)) DiscountID.Identity = True DiscountsTable.Columns.Add(DiscountID) DiscountsTable.Columns.Add(DiscountName) DiscountsTable.Create() End Sub End Module -- Tibor Karaszi, SQL Server MVP http://www.karaszi.com/sqlserver/default.asp http://sqlblog.com/blogs/tibor_karaszi "Lubomir" <Lubomir(a)discussions.microsoft.com> wrote in message news:25B63A6F-5462-449F-8F75-DFF711E24BDA(a)microsoft.com... On Wednesday, August 29, 2007 12:50 PM Lubomi wrote: Hi,Thank you for your time. I figured it out in the meantime. Hi, Thank you for your time. I figured it out in the meantime. The problem was I assigned a wrong value for the Default constraint. While it was a string and accepted by SMO, it wasn't accepted during execution. Surprisingly, when I created the script with the Table.Script() method, this error was handled and corrected automatically. Thanks for your interrest, Lubomir "Tibor Karaszi" wrote: On Wednesday, August 29, 2007 1:32 PM Tibor Karaszi wrote: Re: Create a table with SMO Thanks for letting us know... -- Tibor Karaszi, SQL Server MVP http://www.karaszi.com/sqlserver/default.asp http://sqlblog.com/blogs/tibor_karaszi Submitted via EggHeadCafe - Software Developer Portal of Choice WPF Circular Progress Indicator http://www.eggheadcafe.com/tutorials/aspnet/4d89b4cb-ba59-4362-ab0a-cc047643fd42/wpf-circular-progress-ind.aspx |