Home All Groups Group Topic Archive Search About

Importing DLLs during runtime

Author
5 Oct 2006 8:02 AM
normanchong
Hi,

I'm currently developing an application for checking and doing some
configurations for another application. During those checks, I have to
access SQLServer to get configuration-info like MaxServerMemory,
MaxDegreeOfParallelism, etc

I added the references for
- Microsoft.SqlServer.ConnectionInfo and
- Microsoft.SqlServer.Smo
to my project and then imported the namespaces
- Microsoft.SqlServer.Management.Smo and
- Microsoft.SqlServer.Management.Common
and used their classes 'Server' and 'ServerConnection' to do the job

Everythink works fine, but the problem is, that the DLLs
- Microsoft.SqlServer.Replication and
- Microsoft.SqlServer.BatchParser
are now needed (and added to my project)

This wouldn't be a problem, but I wondered what happens when SQLServer
is not installed and the DLLs are missing.
Long story short: I want to get rid of the imports and do some kind of
DLL-Late-Binding, so I can react to missing DLLs within my program.
I tried to use the 'DLLImport' but I don't know much about that...So
can anyone tell me how to get the 2 classes I need (Server,
ServerConnection)?

P.S.: I'm a newbie, so keep your answers (and perhaps examples) as
simple as possible ;-)

Author
5 Oct 2006 11:07 AM
rowe_newsgroups
> I tried to use the 'DLLImport' but I don't know much about that...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html/vaconCallingWindowsAPIs.asp

Thanks,

Seth Rowe

normanch***@freenet.de wrote:
Show quoteHide quote
> Hi,
>
> I'm currently developing an application for checking and doing some
> configurations for another application. During those checks, I have to
> access SQLServer to get configuration-info like MaxServerMemory,
> MaxDegreeOfParallelism, etc
>
> I added the references for
> - Microsoft.SqlServer.ConnectionInfo and
> - Microsoft.SqlServer.Smo
> to my project and then imported the namespaces
> - Microsoft.SqlServer.Management.Smo and
> - Microsoft.SqlServer.Management.Common
> and used their classes 'Server' and 'ServerConnection' to do the job
>
> Everythink works fine, but the problem is, that the DLLs
> - Microsoft.SqlServer.Replication and
> - Microsoft.SqlServer.BatchParser
> are now needed (and added to my project)
>
> This wouldn't be a problem, but I wondered what happens when SQLServer
> is not installed and the DLLs are missing.
> Long story short: I want to get rid of the imports and do some kind of
> DLL-Late-Binding, so I can react to missing DLLs within my program.
> I tried to use the 'DLLImport' but I don't know much about that...So
> can anyone tell me how to get the 2 classes I need (Server,
> ServerConnection)?
>
> P.S.: I'm a newbie, so keep your answers (and perhaps examples) as
> simple as possible ;-)
Author
5 Oct 2006 6:30 PM
GhostInAK
On 5 Oct 2006 01:02:31 -0700, normanch***@freenet.de wrote:

First off, DllImport Will Fail, those two files are .NET assemblies -
not Win32 DLLs.

Second off, use the imports.  The app will toss an exception if the
required DLLs are missing and you can then correct the problem.

-Boo

Show quoteHide quote
>Hi,
>
>I'm currently developing an application for checking and doing some
>configurations for another application. During those checks, I have to
>access SQLServer to get configuration-info like MaxServerMemory,
>MaxDegreeOfParallelism, etc
>
>I added the references for
>- Microsoft.SqlServer.ConnectionInfo and
>- Microsoft.SqlServer.Smo
>to my project and then imported the namespaces
>- Microsoft.SqlServer.Management.Smo and
>- Microsoft.SqlServer.Management.Common
>and used their classes 'Server' and 'ServerConnection' to do the job
>
>Everythink works fine, but the problem is, that the DLLs
>- Microsoft.SqlServer.Replication and
>- Microsoft.SqlServer.BatchParser
>are now needed (and added to my project)
>
>This wouldn't be a problem, but I wondered what happens when SQLServer
>is not installed and the DLLs are missing.
>Long story short: I want to get rid of the imports and do some kind of
>DLL-Late-Binding, so I can react to missing DLLs within my program.
>I tried to use the 'DLLImport' but I don't know much about that...So
>can anyone tell me how to get the 2 classes I need (Server,
>ServerConnection)?
>
>P.S.: I'm a newbie, so keep your answers (and perhaps examples) as
>simple as possible ;-)
Author
10 Oct 2006 10:56 AM
normanchong
GhostInAK schrieb:

> On 5 Oct 2006 01:02:31 -0700, normanch***@freenet.de wrote:
>
> First off, DllImport Will Fail, those two files are .NET assemblies -
> not Win32 DLLs.

That's right - sorry, DllImport = stupid idea (Like I wrote: I'm a
newbie ;-) )

> Second off, use the imports.  The app will toss an exception if the
> required DLLs are missing and you can then correct the problem.

When I start my application without those dlls, a dialog with the
exception-message appears but that doesn't seem to be the best
solution...Isn't there a way to bind the assemblies during runtime?
I tried to use
Reflection.Assembly.load(Microsoft.SqlServer.Replication) but it
doesn't seem that I can access the classes 'Server' and
'ServerConnection' with this. So I used
Reflection.Assembly.load(Microsoft.SqlServer.Smo) but that threw an
exception...

I wondered why I need the .Replication.dll \ BatchParser.dll because
the two assemblies refer to .Smo.dll \ .ConnectionInfo.dll ?!?