Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. To modify table column.

To modify table column.

Scheduled Pinned Locked Moved C#
databasesql-serversysadminhelp
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kmb89
    wrote on last edited by
    #1

    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

    S M 2 Replies Last reply
    0
    • K kmb89

      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

      S Offline
      S Offline
      SeMartens
      wrote on last edited by
      #2

      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.

      K 1 Reply Last reply
      0
      • S SeMartens

        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.

        K Offline
        K Offline
        kmb89
        wrote on last edited by
        #3

        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."

        S 1 Reply Last reply
        0
        • K kmb89

          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."

          S Offline
          S Offline
          SeMartens
          wrote on last edited by
          #4

          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.

          K 1 Reply Last reply
          0
          • S SeMartens

            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.

            K Offline
            K Offline
            kmb89
            wrote on last edited by
            #5

            Thank for ur reply. My goal is to change the column properties to be the same with other column. I already left "Computed" property but an error has been occur with the other property of the column.

            1 Reply Last reply
            0
            • K kmb89

              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

              M Offline
              M Offline
              Md Marufuzzaman
              wrote on last edited by
              #6

              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.

              M 1 Reply Last reply
              0
              • M Md Marufuzzaman

                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.

                M Offline
                M Offline
                Md Marufuzzaman
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups