SQLDMO in C# - most parts work, why not this? 
Author Message
 SQLDMO in C# - most parts work, why not this?

Hi,
Trying to migrate a VB6 utility all to C#, using lotsa SQLDMO...most parts
work, even though the sysntax changes are quite significant. One part,
dealing with DRIDefaults, is barfing every time, and I just can't figure it
out. Anybody got any hints?

The error is 'Object Reference not set to an instance of an object'
I know that the DB connection is fine, since it works everywhere else, and
the table looping (foreach) also works, but when it gets to the columns, it
becomes extremely lactose intolerant...

The code chunk looks like this:
=======================
DB.Tables.Refresh(null);
foreach (SQLDMO.Table Table in DB.Tables)
{
 if (!Table.SystemObject)
 {
  Table.Columns.Refresh(null);
  foreach (SQLDMO.Column Column in Table.Columns)
  {
   if (Column.DRIDefault.Text.Length > 0)      <======Error here
   {
    SQLDMO.DRIDefault Obj = Column.DRIDefault;
    sTemp = Obj.Script(ScriptSettings, null, 0);
    if (sTemp != null)
      // I do other stuff with the script here
   }
  }
 }

Quote:
}



Wed, 06 Oct 2004 12:18:08 GMT  
 SQLDMO in C# - most parts work, why not this?
Because the Text property is NULL

using System;
using System.Runtime.InteropServices;
using SQLDMO;
namespace test
{
    /// <summary>
    /// Summary description for App.
    /// </summary>
    class App
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [MTAThread]
        static void Main(string[] args)
        {
            try
            {
                SQLDMO.SQLServer2Class sqlserver = new SQLServer2Class();
                sqlserver.LoginSecure = true;
                sqlserver.Connect("(local)\\dev", null, null);

                SQLDMO.Database2 database = (SQLDMO.Database2)
sqlserver.Databases.Item("pubs", null);
                database.Tables.Refresh(null);
                foreach (SQLDMO.Table table in database.Tables)
                {
                    if (! table.SystemObject)
                    {
                        table.Columns.Refresh(null);
                        foreach (SQLDMO.Column column in table.Columns)
                        {
                            SQLDMO.DRIDefault driDefault =
column.DRIDefault;
                            if (driDefault.Text != null &&
driDefault.Text.Length > 0) // <======Error here
                            {
                                Console.WriteLine("{0}", driDefault.Text);
                            }
                        }
                    }
                }
            }
            catch(COMException e)
            {
                Console.WriteLine("COM Exception {0}\n{1}", e.Message,
e.StackTrace);
            }
        }
    }

Quote:
}


Please reply only to the newsgroups.
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.
Copyright ? SQLDev.Net 1991-2002 All rights reserved.


Quote:
> Hi,
> Trying to migrate a VB6 utility all to C#, using lotsa SQLDMO...most parts
> work, even though the sysntax changes are quite significant. One part,
> dealing with DRIDefaults, is barfing every time, and I just can't figure
it
> out. Anybody got any hints?

> The error is 'Object Reference not set to an instance of an object'
> I know that the DB connection is fine, since it works everywhere else, and
> the table looping (foreach) also works, but when it gets to the columns,
it
> becomes extremely lactose intolerant...

> The code chunk looks like this:
> =======================
> DB.Tables.Refresh(null);
> foreach (SQLDMO.Table Table in DB.Tables)
> {
>  if (!Table.SystemObject)
>  {
>   Table.Columns.Refresh(null);
>   foreach (SQLDMO.Column Column in Table.Columns)
>   {
>    if (Column.DRIDefault.Text.Length > 0)      <======Error here
>    {
>     SQLDMO.DRIDefault Obj = Column.DRIDefault;
>     sTemp = Obj.Script(ScriptSettings, null, 0);
>     if (sTemp != null)
>       // I do other stuff with the script here
>    }
>   }
>  }
> }



Thu, 07 Oct 2004 03:09:52 GMT  
 SQLDMO in C# - most parts work, why not this?
Gert,

Thanks - that was it! An easy, obvious solution, now that I see it, but not
so easy to track down...the de{*filter*} would show the Text value as "" instead
of null...Thanks again.

-Meade



Thu, 07 Oct 2004 03:42:35 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. atof(part of a string array) why not?

2. CFile not working properly, can't figure out why (last message not sent properly)

3. SQLDMO problem in C#

4. SQLDMO C# Problem

5. How to access SQLDMO and DSO from C#

6. Crash when trying to access SQLDMO with C#

7. Why don't the System.Console.WriteLine work in C# WinApps

8. why does this code not work?

9. why is this code(2) not working?

10. help:- similar functions work, why not these?

11. Why would the following code not work ?

12. Why does this not work?

 

 
Powered by phpBB® Forum Software