473,394 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to use SQLDMO in C#?

I am trying to use SQLDMO in C# and it's a nightmare.

Any examples, suggestions, is there a different (managed) way to do this
that I don't know about?

Thanks for the help.
Tom Padilla
Nov 17 '05 #1
6 11449
oj
You will need to create an interop for dmo before you can use it. Here are
the steps:

1. add a reference to dmo - browse to sqldmo.dll (normally found under
\tools\binn of sql directory)
2. and here is a simple code to get you started

using System;
using SQLDMO;

namespace dmo2
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
ListSQLs();
}

public static void ListSQLs()
{
//
// List available SQL Server on subnet
//
SQLServer2 oServer = new SQLServer2();
Application oApp = oServer.Application;
NameList oList = oApp.ListAvailableSQLServers();

for (int i=0; i < oList.Count; i++)
{
Console.WriteLine(oList.Item(i));
}
Console.Read();

} //end ListSQLs
}
}

--
-oj
"Henry Padilla" <pa******@hotmail.com> wrote in message
news:Jo**************@newssvr19.news.prodigy.com.. .
I am trying to use SQLDMO in C# and it's a nightmare.

Any examples, suggestions, is there a different (managed) way to do this
that I don't know about?

Thanks for the help.
Tom Padilla

Nov 17 '05 #2

"oj" <no**********@home.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
You will need to create an interop for dmo before you can use it. Here are
the steps:

1. add a reference to dmo - browse to sqldmo.dll (normally found under
\tools\binn of sql directory)
2. and here is a simple code to get you started

using System;
using SQLDMO;

namespace dmo2
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
ListSQLs();
}

public static void ListSQLs()
{
//
// List available SQL Server on subnet
//
SQLServer2 oServer = new SQLServer2();
Application oApp = oServer.Application;
NameList oList = oApp.ListAvailableSQLServers();

for (int i=0; i < oList.Count; i++)
{
Console.WriteLine(oList.Item(i));
}
Console.Read();

} //end ListSQLs
}
}

--
-oj


I appreciate the help and it's my fault for leaving this an open-ended
question. Let me try again.

I am trying to make a mini-Enterprise Manager and so far I can get the
server groups and list the registered servers but when I try to get a
specific server from the SQLServers collection (by name) it doesn't return
anything.

This should be possible, right?

Following your example above I should be able to the following:

SQLServer2 currentSQLServer = oApp.SQLServers("DBName")

But for some reason it comes back a null object.

I have no idea how to continue. (Loop through the list until I find the
SQLServer.ServerName = "DBName"?)

Tom P.
Nov 17 '05 #3
oj
You have to connect to the server in order to access its objects.

e.g.
oServer.Connect "myservername","login","password"

I suggest you take a look at this:
http://msdn.microsoft.com/library/en..._ob_s_7igk.asp

Also, here are some sample projects using sqldmo. These should be helpful.
http://www.gotdotnet.com/community/u...x?query=sqldmo
--
-oj
"Henry Padilla" <pa******@hotmail.com> wrote in message
news:mm****************@newssvr31.news.prodigy.com ...

I appreciate the help and it's my fault for leaving this an open-ended
question. Let me try again.

I am trying to make a mini-Enterprise Manager and so far I can get the
server groups and list the registered servers but when I try to get a
specific server from the SQLServers collection (by name) it doesn't return
anything.

This should be possible, right?

Following your example above I should be able to the following:

SQLServer2 currentSQLServer = oApp.SQLServers("DBName")

But for some reason it comes back a null object.

I have no idea how to continue. (Loop through the list until I find the
SQLServer.ServerName = "DBName"?)

Tom P.

Nov 17 '05 #4

"oj" <no**********@home.com> wrote in message
news:OO**************@TK2MSFTNGP15.phx.gbl...
You have to connect to the server in order to access its objects.

e.g.
oServer.Connect "myservername","login","password"

Unless I know if this is a secure server how do I connect to it?
But I can't get any info from the Application object regarding a particular
server.

I suggest you take a look at this:
http://msdn.microsoft.com/library/en..._ob_s_7igk.asp

Also, here are some sample projects using sqldmo. These should be helpful.
http://www.gotdotnet.com/community/u...x?query=sqldmo

Unfortunately those didn't help much. One is just the Microsoft site that
doesn't explain anything (or is just plain wrong I don't know which). The
other only uses SQLDMO to get a list of servers. I've got the list, but it
doesn't do me any good unless I can connect to them.
--
-oj

Tom P.
Nov 17 '05 #5
oj
The Application object is just a shell. The connection/security info is part
of the Server object and you cannot access it unless you've successfully
connected to the server. This is by design else this would be a major
security hole!

Anyway, here is example using trusted authentication.
http://msdn.microsoft.com/library/en...con03_8q44.asp

--
-oj
"Henry Padilla" <pa******@hotmail.com> wrote in message
news:Wj****************@newssvr17.news.prodigy.com ...

"oj" <no**********@home.com> wrote in message
news:OO**************@TK2MSFTNGP15.phx.gbl...
You have to connect to the server in order to access its objects.

e.g.
oServer.Connect "myservername","login","password"


Unless I know if this is a secure server how do I connect to it?
But I can't get any info from the Application object regarding a
particular server.

I suggest you take a look at this:
http://msdn.microsoft.com/library/en..._ob_s_7igk.asp

Also, here are some sample projects using sqldmo. These should be
helpful.
http://www.gotdotnet.com/community/u...x?query=sqldmo

Unfortunately those didn't help much. One is just the Microsoft site that
doesn't explain anything (or is just plain wrong I don't know which). The
other only uses SQLDMO to get a list of servers. I've got the list, but
it doesn't do me any good unless I can connect to them.
--
-oj

Tom P.

Nov 17 '05 #6

"oj" <no**********@home.com> wrote in message
news:eH*************@TK2MSFTNGP15.phx.gbl...
The Application object is just a shell. The connection/security info is
part of the Server object and you cannot access it unless you've
successfully connected to the server. This is by design else this would be
a major security hole!

Anyway, here is example using trusted authentication.
http://msdn.microsoft.com/library/en...con03_8q44.asp

--
-oj


Thanks, I found a "Login" demo in the SQL Server directory and they try to
connect both ways and use whichever way works. Yep, there's an if()
statement that if connecting with secure login doesn't work try it with the
supplied user name and password.

Looks like that's my recourse.

Thanks for sticking with me through this. You were a big help.
Tom P.
Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ewm | last post by:
Using InstallShield Developer 7.04. Does anyone know of a good way to detect if SQLDMO is installed? TIA mcpoo
1
by: Mohammed Abdel-Razzak | last post by:
Dear sirs I`ve used SQLDMO to make a backup to my database How can I use it to restore database? thanks Mohammed
3
by: T. | last post by:
I dumped VB and adopted C# for this version of Visual Studio. My problem! I am trying to reference an SQLDMO.Database object in C# like so: private SQLDMO.Database dbcurrent; private string...
1
by: C# beginner | last post by:
Hi all, I am using SQLDMO.Backup for backing up SQL server databases. I need to implement a progress bar to show the progress. I have some sample VB code that is like this: Dim WithEvents...
1
by: | last post by:
Hi all My requirement is to "on button_click, backup a SQL database using SQLDMO.Backup object and update the progress in a ProgressBar. The problem is the progress bar does not update at all...
2
by: | last post by:
Hi all, continued from yesterday's posting... I still haven't found a solution to this issue. I put a breakpoint in private void SqlBackupPercentComplete(string message, int Percent) {...
1
by: | last post by:
Hi all I am posting this to check if anyone could help me. The problem still persists. I am beginner in C#. Thanks. Subject: SQLDMO.Backup and ProgressBar - help please From: ...
0
by: Craig G | last post by:
i have a small application that uses the SQLDMO com object when i build a setup package to distribute it adds both the Interop.SQLDMO.dll assembly & sqldmo.dll File the problem is that the...
6
by: Craig G | last post by:
how the hell do i get this to register?!?!? my test pc is running XP & MDAC 2.8 but still it wont register SQLDMO.dll and is therefore preventing my application from running and i dont want...
3
by: Brian Henry | last post by:
Anyone know why this would happen... I added a reference to the SQLDMO COM object, imported it on top of my code.. then this test code fails Imports SQLDMO Module Module1 Sub Main() Dim...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.