Results 1 to 11 of 11

Thread: [RESOLVED] Help in getting list of MS SQL servers and Database

  1. #1

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Resolved [RESOLVED] Help in getting list of MS SQL servers and Database

    hi Guys! Can you help me on how can to get a list of MS SQL servers, regardless of version, present in my network or computer and the available database in that particular Server? Thanks in advance! Oh! I forgot SQLDMO is not working to me it does not get any list of available ms sql server, though im sure that some ms sql server is present in our network.
    Last edited by daimous; Jun 25th, 2007 at 01:58 AM.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Help in getting list of MS SQL servers and Database

    Although thi sis VB its still the same class in .NET.

    http://vbforums.com/showpost.php?p=1928800&postcount=2
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: Help in getting list of MS SQL servers and Database

    Thanks for that RobDog...but SQLDMO is not working to me. Is there any posible way aside from using SQLDMO?

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Help in getting list of MS SQL servers and Database

    You need to add a reference or import the namespace. I cant test it yet as I dont have sql installed.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: Help in getting list of MS SQL servers and Database

    Already done that..Actually i used SQLDMO to backup and restore my database but using it to get list of available ms sql server and database to that particular server is no luck..

  6. #6

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: Help in getting list of MS SQL servers and Database

    Its now already working using SQLDMO...Thanks a lot!

  7. #7

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: Help in getting list of MS SQL servers and Database

    Now it has an error again..hope this is not a major problem..I'va created a function that would return an array of string that contains the list of MS SQL server but when i call that function it has an error..can you help me to figure it out? Thanks!

    Code:
            public static string[] GetSqlServerList()
            {
                string[] SqlServerList = null;
                try
                {
                    SQLDMO.Application SqlApp = new SQLDMO.Application();
                    SQLDMO.NameList SqlServers;
                    SqlServers = SqlApp.ListAvailableSQLServers();
                    for (int i = 0; i <= SqlServers.Count - 1; i++)
                    {
                        if (SqlServers.Item(i) != null)
                        {
                            SqlServerList[i] = SqlServers.Item(i).ToString();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error getting SQL Server list!\r\nMessage:" + ex.Message, "RCPS [Server List]",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return SqlServerList;
            }
    ERROR:
    System.NullReferenceException was unhandled
    Message="Object reference not set to an instance of an object."
    Source="RCPSProject"
    StackTrace:
    at RCPSProject.CommonFunctions.GetSqlServerList() in C:\Documents and Settings\absalvamante\My Documents\Visual Studio 2005\Projects\RCPSProject\RCPSProject\Common\CommonFunctions.cs:line 182
    at RCPSProject.RCPSIndex.BtnRenew_Click(Object sender, EventArgs e) in C:\Documents and Settings\absalvamante\My Documents\Visual Studio 2005\Projects\RCPSProject\RCPSProject\RCPSIndex.cs:line 62
    at System.Windows.Forms.Control.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
    at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ButtonBase.WndProc(Message& m)
    at System.Windows.Forms.Button.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
    at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
    at System.Windows.Forms.Application.Run(Form mainForm)
    at RCPSProject.Program.Main() in C:\Documents and Settings\absalvamante\My Documents\Visual Studio 2005\Projects\RCPSProject\RCPSProject\Program.cs:line 17
    at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
    at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
    at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
    at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Threading.ThreadHelper.ThreadStart()
    Last edited by daimous; Jun 25th, 2007 at 04:10 AM.

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Help in getting list of MS SQL servers and Database

    Try placing the sercver count - 1 into a variable before hte loop.

    integer iTemp = SqlServers.Count - 1

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: Help in getting list of MS SQL servers and Database

    i got it working..Instead of array of string i just use List<string>..
    Code:
            public static List<string> GetSqlServerList()
            {
                List<string> ServerList = new List<string>();
                try
                {
                    SQLDMO.Application SqlApp = new SQLDMO.Application();
                    SQLDMO.NameList SqlServers;
                    SqlServers = SqlApp.ListAvailableSQLServers();
                    for (int i = 0; i <= SqlServers.Count - 1; i++)
                    {
                        if (SqlServers.Item(i) != null)
                        {
                            ServerList.Add(SqlServers.Item(i));
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error getting SQL Server list!\r\nMessage:" + ex.Message, "RCPS [Server List]",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return ServerList;
            }
    Anyway, Thanks for the inputs!

  10. #10

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: Help in getting list of MS SQL servers and Database

    RobDog, From the link you gave me above..what if i want to use Windows Authentication instead of SQL Server Authentication how can I do that? Thanks!

  11. #11

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: Help in getting list of MS SQL servers and Database

    I already got it..I just use
    Code:
                        sqlServer.LoginSecure = true;
                        sqlServer.Connect(ServerName, "", "");

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width