To modify table column.
-
I used SMO to manage SQL server 2005. I want to modify a column to be same with other column. I used the following code but it has error while calling Column.Alter() function.
public void RepairColumns(object dcolumn) { try { Column d_Column = (Column)dcolumn; Column l_Column = mServer.Databases[mSMOInfo.DBName].Tables[mSMOInfo.TableIndex].Columns[mSMOInfo.ColumnIndex]; l_Column.Initialize(true); ////l_Column.AnsiPaddingStatus = d_Column.AnsiPaddingStatus; l_Column.Collation = d_Column.Collation; l_Column.Computed = d_Column.Computed; l_Column.ComputedText = d_Column.ComputedText; l_Column.DataType = d_Column.DataType; l_Column.Default = d_Column.Default; l_Column.Identity = d_Column.Identity; string str = d_Column.Properties[1].Name; l_Column.IdentityIncrement = d_Column.IdentityIncrement; l_Column.IdentitySeed = d_Column.IdentitySeed; l_Column.NotForReplication = d_Column.NotForReplication; l_Column.Nullable = d_Column.Nullable; l_Column.RowGuidCol = d_Column.RowGuidCol; l_Column.Rule = d_Column.Rule; l_Column.RuleSchema = d_Column.RuleSchema; ////l_Column.IsFullTextIndexed = d_Column.IsFullTextIndexed; l_Column.IsPersisted = d_Column.IsPersisted; l_Column.DefaultSchema = d_Column.DefaultSchema; l_Column.Alter(); } catch (SmoException ex) { throw ex; } }
If u knows my mistakes, pls point me. Thanks
-
I used SMO to manage SQL server 2005. I want to modify a column to be same with other column. I used the following code but it has error while calling Column.Alter() function.
public void RepairColumns(object dcolumn) { try { Column d_Column = (Column)dcolumn; Column l_Column = mServer.Databases[mSMOInfo.DBName].Tables[mSMOInfo.TableIndex].Columns[mSMOInfo.ColumnIndex]; l_Column.Initialize(true); ////l_Column.AnsiPaddingStatus = d_Column.AnsiPaddingStatus; l_Column.Collation = d_Column.Collation; l_Column.Computed = d_Column.Computed; l_Column.ComputedText = d_Column.ComputedText; l_Column.DataType = d_Column.DataType; l_Column.Default = d_Column.Default; l_Column.Identity = d_Column.Identity; string str = d_Column.Properties[1].Name; l_Column.IdentityIncrement = d_Column.IdentityIncrement; l_Column.IdentitySeed = d_Column.IdentitySeed; l_Column.NotForReplication = d_Column.NotForReplication; l_Column.Nullable = d_Column.Nullable; l_Column.RowGuidCol = d_Column.RowGuidCol; l_Column.Rule = d_Column.Rule; l_Column.RuleSchema = d_Column.RuleSchema; ////l_Column.IsFullTextIndexed = d_Column.IsFullTextIndexed; l_Column.IsPersisted = d_Column.IsPersisted; l_Column.DefaultSchema = d_Column.DefaultSchema; l_Column.Alter(); } catch (SmoException ex) { throw ex; } }
If u knows my mistakes, pls point me. Thanks
Hi, could you post the error message? This would help us to understand the problem a bit better. Regards Sebastian
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
-
Hi, could you post the error message? This would help us to understand the problem a bit better. Regards Sebastian
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
I use adventurework database. Error is FailedOperationException - "Alter failed for Column 'SystemInformationID'." InnerExcetpion - "Modifying the Computed property of the Column object is not allowed. You must drop and recreate the object with the desired property."
-
I use adventurework database. Error is FailedOperationException - "Alter failed for Column 'SystemInformationID'." InnerExcetpion - "Modifying the Computed property of the Column object is not allowed. You must drop and recreate the object with the desired property."
Setting the computed property does only work if you drop and add the column. (As the error message is saying): http://www.windows-tech.info/15/83beeb9f84f9b78a.php[^] Do you need to change the computed value of the column? If not, just leave the line
l_Column.Computed = d_Column.Computed;
out.
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
-
Setting the computed property does only work if you drop and add the column. (As the error message is saying): http://www.windows-tech.info/15/83beeb9f84f9b78a.php[^] Do you need to change the computed value of the column? If not, just leave the line
l_Column.Computed = d_Column.Computed;
out.
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
-
I used SMO to manage SQL server 2005. I want to modify a column to be same with other column. I used the following code but it has error while calling Column.Alter() function.
public void RepairColumns(object dcolumn) { try { Column d_Column = (Column)dcolumn; Column l_Column = mServer.Databases[mSMOInfo.DBName].Tables[mSMOInfo.TableIndex].Columns[mSMOInfo.ColumnIndex]; l_Column.Initialize(true); ////l_Column.AnsiPaddingStatus = d_Column.AnsiPaddingStatus; l_Column.Collation = d_Column.Collation; l_Column.Computed = d_Column.Computed; l_Column.ComputedText = d_Column.ComputedText; l_Column.DataType = d_Column.DataType; l_Column.Default = d_Column.Default; l_Column.Identity = d_Column.Identity; string str = d_Column.Properties[1].Name; l_Column.IdentityIncrement = d_Column.IdentityIncrement; l_Column.IdentitySeed = d_Column.IdentitySeed; l_Column.NotForReplication = d_Column.NotForReplication; l_Column.Nullable = d_Column.Nullable; l_Column.RowGuidCol = d_Column.RowGuidCol; l_Column.Rule = d_Column.Rule; l_Column.RuleSchema = d_Column.RuleSchema; ////l_Column.IsFullTextIndexed = d_Column.IsFullTextIndexed; l_Column.IsPersisted = d_Column.IsPersisted; l_Column.DefaultSchema = d_Column.DefaultSchema; l_Column.Alter(); } catch (SmoException ex) { throw ex; } }
If u knows my mistakes, pls point me. Thanks
Well... Do you change any default settings of your database server... Can you alter any table in design mode....Let me know.
Thanks Md. Marufuzzaman
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
-
Well... Do you change any default settings of your database server... Can you alter any table in design mode....Let me know.
Thanks Md. Marufuzzaman
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
This is me opinion...for this purpose you can use a storedProcedure.
Thanks Md. Marufuzzaman
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.