Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Assembly loading error

Reply
 
Old 03-27-2008   #1 (permalink)
Michael R.


 
 

Assembly loading error

If i execute follwing code within a script test.ps1 i got following error.:

New-Object : Cannot find type
[Microsoft.SqlServer.Management.Common.ServerConnection]: make sure the
assembly containing this type is loaded.

But this happens just for the first execution of this script. Each other try
in the same powershell window there is no error.

Thanks for any help
Michael R.


Code:
---------------------------------------------------------------------------------------------
[System.Reflection.Assembly]::LoadFile("C:\Program Files\Microsoft SQL
Server\90\SDK\Assemblies\Microsoft.SqlServer.Smo.dll")


$smoServerConnection = New-Object
Microsoft.SqlServer.Management.Common.ServerConnection;

$smoServerConnection.ServerInstance = 'serverName';
$smoServerConnection.LoginSecure = $false;
$smoServerConnection.Login = 'xxx';
$smoServerConnection.Password = 'xxx';

$serverConnection = New-Object
Microsoft.SqlServer.Management.Smo.Server($smoServerConnection);
---------------------------------------------------------------------------------------------

My System SpecsSystem Spec
Old 03-27-2008   #2 (permalink)
Shay Levi


 
 

Re: Assembly loading error



Try to load it using PartialName:

[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")



-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> If i execute follwing code within a script test.ps1 i got following
> error.:
>
> New-Object : Cannot find type
> [Microsoft.SqlServer.Management.Common.ServerConnection]: make sure
> the assembly containing this type is loaded.
>
> But this happens just for the first execution of this script. Each
> other try in the same powershell window there is no error.
>
> Thanks for any help
> Michael R.
> Code:
> ----------------------------------------------------------------------
> -----------------------
> [System.Reflection.Assembly]::LoadFile("C:\Program Files\Microsoft SQL
> Server\90\SDK\Assemblies\Microsoft.SqlServer.Smo.dll")
>
> $smoServerConnection = New-Object
> Microsoft.SqlServer.Management.Common.ServerConnection;
>
> $smoServerConnection.ServerInstance = 'serverName';
> $smoServerConnection.LoginSecure = $false; $smoServerConnection.Login
> = 'xxx'; $smoServerConnection.Password = 'xxx';
>
> $serverConnection = New-Object
> Microsoft.SqlServer.Management.Smo.Server($smoServerConnection);
> ----------------------------------------------------------------------
> -----------------------
>

My System SpecsSystem Spec
Old 03-27-2008   #3 (permalink)
RichS


 
 

RE: Assembly loading error

I use

$null =
[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo")
$null =
[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoEnum")
$null = [reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")

in scripts and do not see any issues
--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"Michael R." wrote:
Quote:

> If i execute follwing code within a script test.ps1 i got following error.:
>
> New-Object : Cannot find type
> [Microsoft.SqlServer.Management.Common.ServerConnection]: make sure the
> assembly containing this type is loaded.
>
> But this happens just for the first execution of this script. Each other try
> in the same powershell window there is no error.
>
> Thanks for any help
> Michael R.
>
>
> Code:
> ---------------------------------------------------------------------------------------------
> [System.Reflection.Assembly]::LoadFile("C:\Program Files\Microsoft SQL
> Server\90\SDK\Assemblies\Microsoft.SqlServer.Smo.dll")
>
>
> $smoServerConnection = New-Object
> Microsoft.SqlServer.Management.Common.ServerConnection;
>
> $smoServerConnection.ServerInstance = 'serverName';
> $smoServerConnection.LoginSecure = $false;
> $smoServerConnection.Login = 'xxx';
> $smoServerConnection.Password = 'xxx';
>
> $serverConnection = New-Object
> Microsoft.SqlServer.Management.Smo.Server($smoServerConnection);
> ---------------------------------------------------------------------------------------------
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Loading .net assembly from VB6 code call .NET General
Manual assembly loading necessary? PowerShell
Problem loading an assembly referencing a non-.NET dll PowerShell
Loading assembly dependencies with Powershell PowerShell
Loading 3rd party .NET assembly PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46