Type 'ConnectionOptions' is not defined

A

Andreas Semmelmann

Hello.

I´ve following Problem. I try to use WMI in an ASP.NET Site. But I get still
this error:




Server Error in '/ServerMon' Application.
----------------------------------------------------------------------------
----

Compilation Error
Description: An error occurred during the compilation of a resource required
to service this request. Please review the following specific error details
and modify your source code appropriately.

Compiler Error Message: BC30002: Type 'ConnectionOptions' is not defined.

Source Error:


Line 1: Dim Options As New ConnectionOptions()


Source File: D:\Inetpub\wwwroot\ServerMon\Default.aspx Line: 1

How must i define the Connection Options. I´ve declared it! See below. I´m
new to ASP.NET/VB.NET.

I used the following Code:
<%@ Page Language="VB" %>
<%@ Import Namespace=System.Diagnostics %>
<script runat="server">

Sub Page_Load(Sender as Object, e as EventArgs)


Dim Options As New ConnectionOptions()
options.Username = "dom\user"
options.Password = "password"

Dim Scope As New ManagementScope("\\mcntr2\root\cimv2", options)
Dim strSVCquery As String =
ConfigurationSettings.AppSettings("NICquery")

Dim objNICQuery As New wqlObjectQuery(strSVCquery)
Dim objNICsearcher As New ManagementObjectSearcher(scope, objNICQuery)

Dim envVar As New ManagementObject()
Dim objNICItem As PropertyData
Dim strNICColName As String

scope.connect

For Each envVar in objNICSearcher.Get
For Each objNICItem in envVar.Properties
strNICColName = objNICItem.Name
Next
Next


End Sub
 
N

Natty Gur

Hi,

you probebly missing reference to System.Management.dll assembly.

Natty Gur, CTO
Dao2Com Ltd.
34th Elkalay st. Raanana
Israel , 43000
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
 
A

Andreas Semmelmann

Hi Natty

I´ve imported the System.Managment. I´ve used the following code:

<%@ Page Language="VB" Debug="true" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.IO" %>
<%@ import Namespace="System.Management" %>
<script runat="server">

Sub Page_Load(obj as object, e as eventargs)

On Error Resume Next

'This script uses Windows Management Instrumentation (WMI)
'to return a list of properties for the a specified drive
'attached to the server.
Dim sDriveLetter As String
Dim DiskProperties As PropertyDataCollection
Dim DiskProperty

'Drive letter for which to show drive properties
sDriveLetter = "C:"

Dim disk As New ManagementObject("win32_logicaldisk.deviceid=""" &
_
sDriveLetter & """")
disk.Get()

Response.write("<H2>Properties of Drive " & sDriveLetter & "</H2>")

'Retrieve the disk's properties
DiskProperties = disk.Properties

'Iterate through the disk's properties
For Each DiskProperty In DiskProperties

'Check whether the particular property is defined for this
drive
If IsDBNull(DiskProperty.Value.ToString()) Then
Response.Write("<FONT COLOR=""blue"">" & DiskProperty.Name &
_
"</FONT> = &lt;not defined&gt;<BR>")

Else

Response.Write("<FONT COLOR=""blue"">" & DiskProperty.Name &
_
"</FONT> = <FONT COLOR=""red"">" & _
DiskProperty.Value.ToString() & "</FONT><BR>")
End If


Next

disk = nothing

End Sub
 
N

Natty Gur

Hi,

You import the System.Managment but that’s no enough. Imports simply let
you access class without full name (using namespace). To enable ASP.NET
to know type a reference to the assembly that holds that type is
necessary. Add reference by using "Add reference" sub menu under
"project" menu.

Natty Gur, CTO
Dao2Com Ltd.
34th Elkalay st. Raanana
Israel , 43000
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
 
A

Andreas Semmelmann

Hi.

Are these settings for Visual Studio .NET? I think so. Do you know the
aproppriate setting for ASP.NET Web Matrix?
As I told you in a former posting, I´m very new to .NET programming. You
must talk to me like I was a fool! Thanks a lot.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top