473,320 Members | 2,006 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,320 software developers and data experts.

C# COM Object Issues

Hi all,

At a high level here is what is going on -- I built a C# COM object. I need to call this com object from SQL Server using the sp_OACreate stored procedure in SQL Server. I build the COM object, register it using regasm, but when I try to call it in SQL Server I get the following error message - "0x80070002 Extended Procedure The system cannot find the file specified." I have tried registering the DLL with regsvr32 and that returns the message "fsi.dll was loaded, but the DllRegisterServer entry point was not found. DllRegisterServer may not be exported, or a corrupt version of fsi.dll may be in memory. Consider using PView to detect and remove it." Well I checked PView and there are no fsi.dll in memory. So, what my hopes are that someone has built a COM object in .NET, registered it, and was able to call it using sp_OACreate. Any help or ideas at this point would be greatly appreciated.

Step 1 (C# COM Source Code [compiled with COM Interoptibility set to true]
-----------------------------------------------------
using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;
namespace fsi
{
public class com : System.ComponentModel.Component
{
private System.ComponentModel.Container components = null;
public static void Main()
{

}

public static void Main(string[] args)
{

}

public com(System.ComponentModel.IContainer container)
{
///
/// Required for Windows.Forms Class Composition Designer support
///
container.Add(this);
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}
public com()
{
///
/// Required for Windows.Forms Class Composition Designer support
///
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

public string test()
{
return "Success";
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}
Step 2 (Register dll on server with regasm)
- Returns success

Step 3 (Call base stored procedure on server)
------------------------------------------------------
DECLARE @object int
DECLARE @hr int
DECLARE @src varchar(255), @desc varchar(255)
EXEC @hr = sp_OACreate 'fsi.com', @object OUT
IF @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @object, @src OUT, @desc OUT
SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
RETURN
END
Jul 21 '05 #1
4 8473
My apologies for the second post. When I did the first one I received a failure message that my message did not make it because an error occurred. However, it appears it still did...
Jul 21 '05 #2
Your C# COM object needs to be a class library - your code below looks like
an exe. Something like this in your class library is what it should look
like. Obviously the guids and progid need to match what the client is
expecting. Then run regasm on it. I've no idea how SQL gets to your COM
method, so what follows is a guess, but if it really is COM it will require
a Guid or a progid, and I expect it might be late binding, so the parameters
need to be automation-compatible (stick to string, int ! ).

[ComVisible(true), GuidAttribute(" get a unique guid here")]
[ProgId("Your.progid")]
public class someclass
{

public string somemethod ()
{
return "hello";
}
}
--
Phil Wilson [MVP Windows Installer]
----
"gman997" <gm*****@discussions.microsoft.com> wrote in message
news:9C**********************************@microsof t.com...
Hi all,

At a high level here is what is going on -- I built a C# COM object. I need to call this com object from SQL Server using the sp_OACreate stored
procedure in SQL Server. I build the COM object, register it using regasm,
but when I try to call it in SQL Server I get the following error message -
"0x80070002 Extended Procedure The system cannot find the file specified."
I have tried registering the DLL with regsvr32 and that returns the message
"fsi.dll was loaded, but the DllRegisterServer entry point was not found.
DllRegisterServer may not be exported, or a corrupt version of fsi.dll may
be in memory. Consider using PView to detect and remove it." Well I
checked PView and there are no fsi.dll in memory. So, what my hopes are
that someone has built a COM object in .NET, registered it, and was able to
call it using sp_OACreate. Any help or ideas at this point would be greatly
appreciated.
Step 1 (C# COM Source Code [compiled with COM Interoptibility set to true]
-----------------------------------------------------
using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;
namespace fsi
{
public class com : System.ComponentModel.Component
{
private System.ComponentModel.Container components = null;
public static void Main()
{

}

public static void Main(string[] args)
{

}

public com(System.ComponentModel.IContainer container)
{
///
/// Required for Windows.Forms Class Composition Designer support
///
container.Add(this);
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}
public com()
{
///
/// Required for Windows.Forms Class Composition Designer support
///
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

public string test()
{
return "Success";
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}
Step 2 (Register dll on server with regasm)
- Returns success

Step 3 (Call base stored procedure on server)
------------------------------------------------------
DECLARE @object int
DECLARE @hr int
DECLARE @src varchar(255), @desc varchar(255)
EXEC @hr = sp_OACreate 'fsi.com', @object OUT
IF @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @object, @src OUT, @desc OUT
SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
RETURN
END

Jul 21 '05 #3
The methods/properties of your class object that need to be exposed through COM need only be defined as 'public'.

Once your DLL is generated it will need to be installed in the GAC on the target computer for all other programs to use. See http://support.microsoft.com/default...b;en-us;815808.

"gman997" wrote:
Hi all,

At a high level here is what is going on -- I built a C# COM object. I need to call this com object from SQL Server using the sp_OACreate stored procedure in SQL Server. I build the COM object, register it using regasm, but when I try to call it in SQL Server I get the following error message - "0x80070002 Extended Procedure The system cannot find the file specified." I have tried registering the DLL with regsvr32 and that returns the message "fsi.dll was loaded, but the DllRegisterServer entry point was not found. DllRegisterServer may not be exported, or a corrupt version of fsi.dll may be in memory. Consider using PView to detect and remove it." Well I checked PView and there are no fsi.dll in memory. So, what my hopes are that someone has built a COM object in .NET, registered it, and was able to call it using sp_OACreate. Any help or ideas at this point would be greatly appreciated.

Step 1 (C# COM Source Code [compiled with COM Interoptibility set to true]
-----------------------------------------------------
using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;
namespace fsi
{
public class com : System.ComponentModel.Component
{
private System.ComponentModel.Container components = null;
public static void Main()
{

}

public static void Main(string[] args)
{

}

public com(System.ComponentModel.IContainer container)
{
///
/// Required for Windows.Forms Class Composition Designer support
///
container.Add(this);
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}
public com()
{
///
/// Required for Windows.Forms Class Composition Designer support
///
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

public string test()
{
return "Success";
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}
Step 2 (Register dll on server with regasm)
- Returns success

Step 3 (Call base stored procedure on server)
------------------------------------------------------
DECLARE @object int
DECLARE @hr int
DECLARE @src varchar(255), @desc varchar(255)
EXEC @hr = sp_OACreate 'fsi.com', @object OUT
IF @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @object, @src OUT, @desc OUT
SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
RETURN
END

Jul 21 '05 #4
Thanks Guys!! It works, I added the strong name followed by the directions in the knowledge base. I also added the attributes as suggested by Phil. I added the dll to GAC and then ran regasm. Hopped back into SQL Server and bingo it all works. I am listing the updated source code here for reference to others. This is really cool though calling a .NET method from SQL Server with COM.

using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;
namespace fsi
{
using interop = System.Runtime.InteropServices;
[
interop.ComVisible(true),
interop.Guid("78A7E9AD-B31B-3AF0-B931-2E1258CC1BD1")
]

public class com : System.ComponentModel.Component
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public static void Main()
{

}

public static void Main(string[] args)
{

}

public com(System.ComponentModel.IContainer container)
{
///
/// Required for Windows.Forms Class Composition Designer support
///
container.Add(this);
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}
public com()
{
///
/// Required for Windows.Forms Class Composition Designer support
///
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

public string test()
{
return "Success";
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}

Jul 21 '05 #5

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

Similar topics

8
by: Rodd Snook | last post by:
I have an application which makes extensive use of the Scripting.Dictionary object. I'm not doing anything silly like putting them outside the page scope -- just creating quite a few of them and...
2
by: Unruled Boy | last post by:
1.The follow two ways to declare one object: any difference? especially its performance. a.Private m_objMyObject As MyObject=New MyObject() b.Private m_objMyObject As MyObject m_objMyObject=New...
0
by: Craig Rodrigues | last post by:
REQUEST FOR DISCUSSION (RFD) unmoderated group comp.object.corba.tao This is a formal Request For Discussion (RFD) to create comp.object.corba.tao as an unmoderated world-wide Usenet newsgroup...
6
by: solex | last post by:
Hello, I am trying to use serialization to copy objects. The object in question "Institution" inherits from a parent object "Party" both are marked as <Serializable()>. Initially I can copy an...
12
by: Andrew Poulos | last post by:
With the following code I can't understand why this.num keeps incrementing each time I create a new instance of Foo. For each instance I'm expecting this.num to alert as 1 but keeps incrementing. ...
45
by: bigdadro | last post by:
I've created a new class using prototype.js. After I make the ajax.request all references to this.myClassMethodorVariable are lost. Does the ajax method blow out the object persistance? I'm fairly...
13
by: TS | last post by:
Say i have a class car with properties: Color, Make, Model, Year, DriverID And a Driver class with properties: DriverID, Name The driverID PRIVATE property is the id of the driver from say a...
8
by: cj | last post by:
In 2003 I sometimes changed the startup object of a project to Sub Main which was found in Module1.vb. I upgraded one such project to 2005 and I notice in the properties page for the project that...
1
by: =?Utf-8?B?U2NvdHQ=?= | last post by:
Hello, Using VS2008 in a C# web service application, a class has been created that inherits from the ConfigurationSelection. This class file has been placed in the App_Code folder. The...
9
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I am just starting to write some code in C#. One time I accidently used "object" instead of "Object". The program didn't complain at all and worked fine. I am just wondering is there...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.