Showing posts with label smo. Show all posts
Showing posts with label smo. Show all posts

Wednesday, March 21, 2012

generating script with SMO

I am taking my table names and colums from xml file and then generating the script and executing it.I have problem creating the script for incerting table with multiple colums.Maybe the problem is that I am using a for loop to get all column names from a array string.Has anyone idea why it is not working? When I try insert of a table without loop it is wirking!Here is the code :
Server server = new Server(); // Create table in my personal database Database db = server.Databases["new"]; // Make Sure Constraint is Scripted ScriptingOptions so = new ScriptingOptions(); so.IncludeHeaders = true; so.SchemaQualify = true; // Create In-Memory Table Table newTable = new Table(db, Names[0].ToString()); for (int i = 1; i < Names.Length; i++) { Column newColumn = new Column(newTable,NamesIdea); newTable.Columns.Add(newColumn); } foreach (string s in newTable.Script(so)) /// Error generating the script { myTableScript = myTableScript + s; } db.ExecuteNonQuery(myTableScript); //disconnect form Database connection.Close();

Could you please metion the full error you are getting.

Thanks,
Kuntal

|||I fixed the problem.I haven't set the column format and that's why the script was not correctly generated.The loop is functioning now ok. Here is the edit line :Column newColumn = new Column(newTable, attr.Name, DataType.NVarChar(50));Now I can easily take the table and column names from the xml file and directly put them without using array strings.Thanks for yor time :) Have a nice day !

Monday, March 19, 2012

generating ALTER statement with SMO

Is it possible to generate ALTER statement for the stored proc with the SMO?

Any link will be appreciated. Thanks.

Any help please. Or it is not possible at all.|||In practice I always drop an existing stored procedure and recreate it when a change is required. Is there a particular reason why you'd rather alter the procedure?

generating ALTER statement with SMO

Is it possible to generate ALTER statement for the stored proc with the SMO?

Any link will be appreciated. Thanks.

Any help please. Or it is not possible at all.|||In practice I always drop an existing stored procedure and recreate it when a change is required. Is there a particular reason why you'd rather alter the procedure?