Refresh method for Tables Collection

  • Hi,

    I am working with the old code written before 2001. There is a statement that I don't understand:

    oDatabase.oTables.Refresh

    Does anybody know why and/or when it is needed? Is it legacy from SQL Server 6.5 / 7?

    Microsoft did not provide much info, but it says "use caution"...

    These are the details:

    Set oServer = New SQLDMO.SQLServer

    Call oServer.Connect(*****, "****", "****")

    Set oDatabase = oServer.Databases("Mydb")

    Call DropTable(oDatabase, "MyTable")

    vSQL = "create table MyTable (MyField1 varchar (12) not null, MyField2 varchar (30) null)"

    Call oDatabase.ExecuteImmediate(vSQL)

    Call oDatabase.Tables.Refresh

    '/// create other tables, update them, drop them

    '/// but there is only one plase where the Refresh method is called

    Any help will be greatly appreciated!

    Thanks!

    Elena

  • This was removed by the editor as SPAM

  • The Refresh method simply reloads the list of tables into your DMO tables collection from the server.  It has no effect on the server or any object on it.

    To see it in action, open Query Analyzer, and expand a server connection so you can see the list of tables.  Then add a table using EM, QA, whatever.  The new table will not show in your Query Analyzer Object Explorer.  Now, right-click on the "Tables" node in the tree, and choose "Refresh".

    That's the DMO tables.Refresh method at work.   Your code calls the Refresh method to pick up the table change (the drop) it just performed.

    -Eddie

     

    Eddie Wuerch
    MCM: SQL

  • Eddie,

    Thank you for a detailed information.

    One more question: Is there a general rule when the Refresh method should be used? My code has a few drop/create pairs, but refresh is used only once.

    And another one: In multy-user environment, each instance of SQL DMO Database object drops, creates, inserts into, updates and deletes tables (table names are unique in the DB). When one instanse for example inserts data into a table, and another instance "refreshes" the tables, could it cause problems for the first process (inserting)?

    Thank you!

    Elena

     

     

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply