Using C# Class Library in VBScript

G

Guest

Help!

Hi, I'm having a bit (well a lot - it's getting annoying) of trouble using a
C# class library within a VBScript on a computer other than the development
machine. All the class is needed for at the moment is to create an
ADODB.Connection object based on a passed in parameter. The passed in
parameter is looked up in an XML document which then creates a connection
string. It would then return the ADODB.Connection object. So for example,
it would be used from VBScript like this:

Dim adoConn, conn

Set adoConn = CreateObject("MyLib.MyClass")
Set conn = adoConn.Conn("databaseName")
conn.Open
etc...

I understand that I require an interface which contains all the methods and
properties that I wish to use from VBScript. Therefore I have the following:

<Note: A reference to ADODB is imported>
using System;
using System.Runtime.InteropServices;
using ADODB;

[Guid("F100B75D-8DF4-4672-867D-BECF2F844E3A")]
public interface IADOConnection
{
ADODB.ConnectionClass Conn(string alias);
ADODB.ConnectionClass ConnUser(string alias, string user, string pass);
}

Next I have the class which uses the interface - ADOConnection (extract):

using System.Runtime.InteropServices;
using ADODB;

[ComVisible(true), ClassInterface(ClassInterfaceType.None)]
[Guid("9E74AA5C-282E-42d5-A0E8-FB5C3AE48045")]
public class ADOConnection : IADOConnection
{
public ADODB.ConnectionClass Conn(string alias)
{
AuthMode = 0;
Alias = alias;
lookupXML();

return m_conn;
}
public ADODB.ConnectionClass ConnUser(string alias, string user, string pass)
{
Alias = alias;
Username = user;
Password = pass;
AuthMode = 1;
lookupXML();

return m_conn;
}
}

I have generated a KeyFile using sn.exe and placed the path of the file in
the AssemblyInfo.cs file as follows:

[assembly: AssemblyKeyFile("..\\..\\KeyFile.snk")]

I build the project and it goes fine.
I have a test VBscript file on the development machine to use the class. It
works fine. I copy the dll to another machine which has the .NET Framework
installed and also copy the VBscript file. I then run the command:
RegASM.exe /tlb:myAssembly.tlb myAssembly.dll

I get greeted with:

Types registered successfully
RegAsm error: Type library exporter encountered an error while processing
'ObjWa
re.Lib.IADOConnection.Conn(#0), MyAssembly'. Error: Type library exporter
can n
ot load type ADODB.ConnectionClass (error: System.IO.FileNotFoundException:
File
or assembly name ADODB, or one of its dependencies, was not found.
File name: "ADODB"

=== Pre-bind state information ===
LOG: DisplayName = ADODB, Version=7.0.3300.0, Culture=neutral,
PublicKeyToken=b0
3f5f7f11d50a3a
(Fully-specified)
LOG: Appbase = C:\WINNT\Microsoft.NET\Frame

What am I doing wrong? Any questions or more info I can give if needed.

Thanks always,
Jesse
 
P

Patrice

If I understood, your app uses a wrapper to use the ADODB COM compoant from
..NET. IMO this is this wrapper that misses (likely interop.adox.dll).

Patrice

--

Jessard said:
Help!

Hi, I'm having a bit (well a lot - it's getting annoying) of trouble using a
C# class library within a VBScript on a computer other than the development
machine. All the class is needed for at the moment is to create an
ADODB.Connection object based on a passed in parameter. The passed in
parameter is looked up in an XML document which then creates a connection
string. It would then return the ADODB.Connection object. So for example,
it would be used from VBScript like this:

Dim adoConn, conn

Set adoConn = CreateObject("MyLib.MyClass")
Set conn = adoConn.Conn("databaseName")
conn.Open
etc...

I understand that I require an interface which contains all the methods and
properties that I wish to use from VBScript. Therefore I have the following:

<Note: A reference to ADODB is imported>
using System;
using System.Runtime.InteropServices;
using ADODB;

[Guid("F100B75D-8DF4-4672-867D-BECF2F844E3A")]
public interface IADOConnection
{
ADODB.ConnectionClass Conn(string alias);
ADODB.ConnectionClass ConnUser(string alias, string user, string pass);
}

Next I have the class which uses the interface - ADOConnection (extract):

using System.Runtime.InteropServices;
using ADODB;

[ComVisible(true), ClassInterface(ClassInterfaceType.None)]
[Guid("9E74AA5C-282E-42d5-A0E8-FB5C3AE48045")]
public class ADOConnection : IADOConnection
{
public ADODB.ConnectionClass Conn(string alias)
{
AuthMode = 0;
Alias = alias;
lookupXML();

return m_conn;
}
public ADODB.ConnectionClass ConnUser(string alias, string user, string pass)
{
Alias = alias;
Username = user;
Password = pass;
AuthMode = 1;
lookupXML();

return m_conn;
}
}

I have generated a KeyFile using sn.exe and placed the path of the file in
the AssemblyInfo.cs file as follows:

[assembly: AssemblyKeyFile("..\\..\\KeyFile.snk")]

I build the project and it goes fine.
I have a test VBscript file on the development machine to use the class. It
works fine. I copy the dll to another machine which has the .NET Framework
installed and also copy the VBscript file. I then run the command:
RegASM.exe /tlb:myAssembly.tlb myAssembly.dll

I get greeted with:

Types registered successfully
RegAsm error: Type library exporter encountered an error while processing
'ObjWa
re.Lib.IADOConnection.Conn(#0), MyAssembly'. Error: Type library exporter
can n
ot load type ADODB.ConnectionClass (error: System.IO.FileNotFoundException:
File
or assembly name ADODB, or one of its dependencies, was not found.
File name: "ADODB"

=== Pre-bind state information ===
LOG: DisplayName = ADODB, Version=7.0.3300.0, Culture=neutral,
PublicKeyToken=b0
3f5f7f11d50a3a
(Fully-specified)
LOG: Appbase = C:\WINNT\Microsoft.NET\Frame

What am I doing wrong? Any questions or more info I can give if needed.

Thanks always,
Jesse
 
G

Guest

Hi Patrice,

Where do I find that file? I've searched for it on my system and it doesn't
exist. Do I have to add a reference to it? The class is meant to return an
ADODB.Connection object so if that means its a wrapper then yes that is what
I have.

Jesse

Patrice said:
If I understood, your app uses a wrapper to use the ADODB COM compoant from
..NET. IMO this is this wrapper that misses (likely interop.adox.dll).

Patrice

--

Jessard said:
Help!

Hi, I'm having a bit (well a lot - it's getting annoying) of trouble using a
C# class library within a VBScript on a computer other than the development
machine. All the class is needed for at the moment is to create an
ADODB.Connection object based on a passed in parameter. The passed in
parameter is looked up in an XML document which then creates a connection
string. It would then return the ADODB.Connection object. So for example,
it would be used from VBScript like this:

Dim adoConn, conn

Set adoConn = CreateObject("MyLib.MyClass")
Set conn = adoConn.Conn("databaseName")
conn.Open
etc...

I understand that I require an interface which contains all the methods and
properties that I wish to use from VBScript. Therefore I have the following:

<Note: A reference to ADODB is imported>
using System;
using System.Runtime.InteropServices;
using ADODB;

[Guid("F100B75D-8DF4-4672-867D-BECF2F844E3A")]
public interface IADOConnection
{
ADODB.ConnectionClass Conn(string alias);
ADODB.ConnectionClass ConnUser(string alias, string user, string pass);
}

Next I have the class which uses the interface - ADOConnection (extract):

using System.Runtime.InteropServices;
using ADODB;

[ComVisible(true), ClassInterface(ClassInterfaceType.None)]
[Guid("9E74AA5C-282E-42d5-A0E8-FB5C3AE48045")]
public class ADOConnection : IADOConnection
{
public ADODB.ConnectionClass Conn(string alias)
{
AuthMode = 0;
Alias = alias;
lookupXML();

return m_conn;
}
public ADODB.ConnectionClass ConnUser(string alias, string user, string pass)
{
Alias = alias;
Username = user;
Password = pass;
AuthMode = 1;
lookupXML();

return m_conn;
}
}

I have generated a KeyFile using sn.exe and placed the path of the file in
the AssemblyInfo.cs file as follows:

[assembly: AssemblyKeyFile("..\\..\\KeyFile.snk")]

I build the project and it goes fine.
I have a test VBscript file on the development machine to use the class. It
works fine. I copy the dll to another machine which has the .NET Framework
installed and also copy the VBscript file. I then run the command:
RegASM.exe /tlb:myAssembly.tlb myAssembly.dll

I get greeted with:

Types registered successfully
RegAsm error: Type library exporter encountered an error while processing
'ObjWa
re.Lib.IADOConnection.Conn(#0), MyAssembly'. Error: Type library exporter
can n
ot load type ADODB.ConnectionClass (error: System.IO.FileNotFoundException:
File
or assembly name ADODB, or one of its dependencies, was not found.
File name: "ADODB"

=== Pre-bind state information ===
LOG: DisplayName = ADODB, Version=7.0.3300.0, Culture=neutral,
PublicKeyToken=b0
3f5f7f11d50a3a
(Fully-specified)
LOG: Appbase = C:\WINNT\Microsoft.NET\Frame

What am I doing wrong? Any questions or more info I can give if needed.

Thanks always,
Jesse
 

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

Top