|
|
Morning All,
A couple of questions for any remoting gurus out there!
1) How do I return an instance of a different type of object from a server object back to the client
eg: (Psuedo Code!)
ServerObject2 ServerObject1.GetAnotherObject()
{
return new ServerObject2;
}
2) How do I enable two way remoting so I can send an object created on the client back to the server
eg: (Psuedo Code!)
void ServerObject1.UseAClientObject(ClientObject oClientObject)
{
this.ClientObjects.Add(oClientObject);
}
Cheers - James!
James Simpson
Web Developer
imebgo@hotmail.com
P S - This is what part of the alphabet would look like if Q and R were eliminated Mitch Hedberg
|
|
|
|
|
i need to call a function of a C DLL. the function is declared as
_EXTERN int __stdcall MyFunction(HWND hWndParent, LPTSTR lpszRow1, LPTSTR lpszRow2, LPTSTR lpszRow3);
so i've defined in my c# code
[DllImport("library.dll", CharSet=CharSet.Auto)]
protected static extern Int32 MyFunction(int hWndParent, StringBuilder lpszRow1, StringBuilder lpszRow2, StringBuilder lpszRow3);
in the C/C++ code i have to pass 3 strings of 42 chars (8-bit each) and the function fills the tree with some names.
in c# i've created 3 StringBuilder variables and initialized to 42 of both length and max capacity.
When i call the function the strings are written but the problem is that each char of the StringBuilder is of 16-bit so 2 characters are in one.
Is there a way to extract each single char or to define a StringBuilder of 8-bit elements? I've tried to use string and LPTStr parameters for the function but the DLL doesnt seem to copy anything in my strings.
Gianmaria
|
|
|
|
|
i've resolved changing CharSet=CharSet.Auto to CharSet=CharSet.Ansi in the function definition
|
|
|
|
|
Hello and sweetest wishes for everybuddy,
As part of my project in one ASP.NET server application I have to check if some valid IP client node (wich contains an ASP.NET web application itself too) is currently connected to internet or not and decide based on this state.
One way I think about is to put a socket server on the client node and send a connection request for that to see if it will be successful or not.
I wana see other programmers' experienses and suggestions if there is some better way for that or some special pattern in the socket approach.
Please note I need acceptable speed to see check result.
Thank you so much,
- den to fly
---
"Art happens when you least expect it."
|
|
|
|
|
hai there,
i have a block of code that will generate indexoutofrange exception.
but on catch block i will use Exception (super).
in both cases exception will catch.This is one situation where i know the chance.
My question is what is the performace and resource usage variation if i use Exception Class insted of indexoutofrange on above situation.
Sreejith S S Nair
|
|
|
|
|
There is no difference because the exception chain won't be walked until an Exception actually happens. When the chain is walked, the exception that was thrown will be compared to the narrow exceptions first to see if there is a handler, if not, the more general exceptions will be checked locally first, then following the call chain, keep going until a handler is found or not.
If your trying to determine which Exception class to catch, either IndexOutOfRange or Exception, to see which one is faster, the answer should be neither. IndexOutOfRange MIGHT have a very slight speed advantage. You'll just have to test it to find out. How long does it take to catch 100,000 Exceptions compared to 100,000 IndexOutOfRange exceptions?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi every body!
I'm learning about remote object.
In a sample i'm learning there a statement
Type.GetType("SharedAssembly.SharedObj,SharedObj")
all time when this statemet is excuted, it return null
SharedAssembly: namespace.
SharedObj: a class in above namespace.
Could you tell me how can i fix it?
Thanks!
xyz
|
|
|
|
|
Type.GetType("SharedAssembly.SharedObj, SharedAssembly");
For remoting you'd use <a href="http://msdn.microsoft.com/library/?url=/library/en-us/cpref/html/frlrfSystemActivatorClassGetObjectTopic.asp?frame=true" target="_blank">Activator.GetObject</a> . See the example code in the MSDN overview of Client Activation.
Ian Mariano - Bliki | Blog
"We are all wave equations in the information matrix of the universe" - me
|
|
|
|
|
Hi,
I am a newbie in C# and SQL programming, and I have questions regarding autonumber for one of my table coloumn. Please kindly guide me.
I have this one table consisting of JobID, CustomerID, and Date.
On the coloumn JobID, I like to put autonumber there, since JobID coloumn is also my primary key for the table, so null is not allowed.
I first build the Data Adapter, by using design view, and make new stored procedure for that table.
I also changed the property on the column by setting the Identity to YES, Identity Seed to 1, and Identity Increment to 1.
I did run the SQL stored procedure, it gave me the autonumber on coloumn JobID, but when I tried to put the command in my windows form, it game me error: "An unhandled exception of type 'System.NullReferenceException' Occured"
These following are the codes that I put on my windows form.
<br />
jobDA.Fill(jobDS, "table_job");<br />
<br />
DataRow job = jobDS.Tables["table_job"].NewRow();<br />
job["CustomerID"] = cmb_cust.ValueMember;<br />
job["Date"] = date.Value;<br />
tandaterimaDS.Tables["table_job"].Rows.Add(job);<br />
jobDA.Update(jobDS, "table_job");<br />
and these are the store procedure that I have:
<br />
ALTER PROCEDURE programservice.insert_job<br />
(<br />
@JobID int output,<br />
@CustomerID char(20),<br />
@Date datetime<br />
)<br />
AS<br />
SET NOCOUNT OFF;<br />
INSERT INTO dbo.table_job(CustomerID, Date) VALUES (@CustomerID, @Date);<br />
SELECT JobID, CustomerID, Date FROM dbo.tabel_job WHERE (JobID = @JobID)<br />
SET @JobID = SCOPE_IDENTITY()<br />
Please kindly help me with this problem. I've been stuck here for several days.
Thank you very much in advance.
|
|
|
|
|
Swap the last two lines, like so:
ALTER PROCEDURE programservice.insert_job
(
@JobID int output,
@CustomerID char(20),
@Date datetime
)
AS
SET NOCOUNT OFF
INSERT INTO dbo.table_job(CustomerID, Date) VALUES (@CustomerID, @Date);
SET @JobID = SCOPE_IDENTITY()
SELECT JobID, CustomerID, Date FROM dbo.tabel_job WHERE (JobID = @JobID)
It's also probably a good idea to SET NOCOUNT ON , instead of setting it off. With NOCOUNT OFF , SQL Server will send a message back to the client like "1 Rows affected." Some versions of ADO/MDAC will receive this message and generate a null recordset from it. This may be causing your NullReferenceException . Most likely, though, I think the NullReferenceException is happening because your original proc returns a 0-row recordset.
Grim (aka Toby) MCDBA, MCSD, MCP+SB
|
|
|
|
|
You didn't say what line the exception happened on. Also, a more complete code sample would be needed. The sample you provided doesn't have a definition for tandaterimaDS . It looks like your getting a new blank row from jobDS , filling it, then trying to add that row to a different dataset, tandaterimaDS . This won't work. The you created must be added back to the dataset that created it.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I've tried to set the nocount to on (SET NOCOUNT ON) and change the little mistake I have (JobDS), but it still come out in error.
When the error comes out, it highlight this line:
tandaterimaDS.Tables["table_job"].Rows.Add(job);
I am so confused with this problem, because when I run the stored procedure only, it has no problem or error.
|
|
|
|
|
I've already asked this question, but I'll do it again...
The stored procedure probably isn't the problem. Please post a more complete code sample so we can see what your doing.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
The complete code will be very long, but let me explain and send you more detail code.
What I am trying to do is make a form for data input, so the user will select customer from the combo box, and fill the textbox for description of the job. For the date, it will automatically entered.
When the user hit save button, it will create new JobID, and I was hoping to get it print out, but not yet there.
This is the more complete or detail code:
<br />
using System;<br />
using System.Drawing;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Windows.Forms;<br />
using System.Data;<br />
using System.Data.SqlClient;<br />
<br />
namespace Program_Service<br />
{<br />
<br />
public class frm_tandaterima_baru : System.Windows.Forms.Form<br />
{<br />
private System.ComponentModel.Container components = null;<br />
private System.Windows.Forms.Label lbl_customerID;<br />
private System.Windows.Forms.Label lbl_description;<br />
private System.Windows.Forms.TextBox txt_description;<br />
private System.Windows.Forms.ComboBox cmb_cust;<br />
private System.Windows.Forms.Button btn_save;<br />
private System.Windows.Forms.Button btn_newjob;<br />
private System.Windows.Forms.Button btn_exit;<br />
private System.Data.SqlClient.SqlDataAdapter jobDA;<br />
private System.Data.SqlClient.SqlCommand select_job;<br />
private System.Data.SqlClient.SqlCommand update_job;<br />
private System.Data.SqlClient.SqlCommand insert_job;<br />
private System.Data.SqlClient.SqlCommand delete_job;<br />
private Program_Service.ds_parent jobDS;<br />
private System.Data.SqlClient.SqlDataAdapter custDA;<br />
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;<br />
private System.Data.SqlClient.SqlCommand sqlInsertCommand1;<br />
private System.Data.SqlClient.SqlCommand sqlUpdateCommand1;<br />
private System.Data.SqlClient.SqlCommand sqlDeleteCommand1;<br />
<br />
public frm_newjob()<br />
{<br />
InitializeComponent();<br />
}<br />
protected override void Dispose( bool disposing )<br />
{<br />
if( disposing )<br />
{<br />
if(components != null)<br />
{<br />
components.Dispose();<br />
}<br />
}<br />
base.Dispose( disposing );<br />
}<br />
<br />
private void frm_newjob_Activated(object sender, System.EventArgs e)<br />
{<br />
custDA.Fill(jobDS, "table_cust");<br />
this.cmb_cust.Focus();<br />
}<br />
private void btn_save_Click(object sender, System.EventArgs e)<br />
{<br />
jobDA.Fill(jobDS, "table_job");<br />
<br />
DataRow job = jobDS.Tables["table_job"].NewRow();<br />
job["CustomerID"] = cmb_cust.ValueMember;<br />
job["Date"] = date.Value;<br />
job["Description"] = txt_description.Text;<br />
jobDS.Tables["table_job"].Rows.Add(job);<br />
jobDA.Update(jobDS, "table_job");<br />
}<br />
<br />
private void btn_newjob_Click(object sender, System.EventArgs e)<br />
{<br />
this.txt_description.Clear();<br />
}<br />
<br />
private void btn_exit_Click(object sender, System.EventArgs e)<br />
{<br />
this.Close();<br />
}<br />
}<br />
}<br />
All of the component I had in the form are being put by using designer mode.
One change that I've made on the jobDS.xsd is that the column jobID: nillable = true, NullValue = (Null), ReadOnly = True.
Please advice what should I do, and thank you very much for your attention and help.
|
|
|
|
|
From what I can piece together from your submissions, your calling the Update method on the dataadapter, but using an INSERT SQL statement on that command. If your using an INSERT statement, are you also running a SELECT command after the INSERT so that dataset gets updated and you receive the new record with it's jobID? The jobID won't get created until the new data is commited to the SQL database.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I thought I already have SELECT Command after INSERT on the stored procedure.
Do I need to add another one?
This is my stored procedure for the insert command:
<br />
ALTER PROCEDURE programservice.insert_job<br />
(<br />
@JobID int output,<br />
@CustomerID char(20),<br />
@Date datetime<br />
)<br />
AS<br />
SET NOCOUNT OFF;<br />
INSERT INTO dbo.table_job(CustomerID, Date) VALUES (@CustomerID, @Date);<br />
SELECT JobID, CustomerID, Date FROM dbo.tabel_job WHERE (JobID = @JobID)<br />
SET @JobID = SCOPE_IDENTITY()<br />
I still don't understand why can't I set null to the JobID dataset, since I already set the niilable properties to TRUE.
Is it possible to update or insert the data without the usage of Dataset? Since this is stored procedure, and I believe that the process took place on the database / Server.
Also, is there another way of creating autonumber ID like in this case?
The Database are very likely to be processed by more than one client at the same time.
|
|
|
|
|
Like the first responder said in your post, you SQL statement IS wrong. You said you corrected it, but you changed it back to the incorrect statement again:
ALTER PROCEDURE programservice.insert_job(
@JobID int output,
@CustomerID char(20),
@Date datetime
) AS
SET NOCOUNT ON
INSERT INTO dbo.table_job(CustomerID, Date) VALUES (@CustomerID, @Date);
SET @JobID = SCOPE_IDENTITY()
SELECT JobID, CustomerID, Date FROM dbo.tabel_job WHERE (JobID = @JobID)
The JobID will not have a number until SQL commits the new record to the database (the INSERT statement). Then you can get the new JobID into @JobID using SCOPE_IDENTITY(). Then the SELECT statement returns the updated record to the caller as the sole record in the dataset.
Since JobID is the Primary Key and IDENTITY, it CAN'T ever be NULL...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I figured out the problem already. It was the dataset.
I tried to delete and start from beginning again, create the dataadapter, but this time, I did not generate dataset.
So, First I delete the table from SQL Server, and then create new one with the same name.
I change the property of the table in design mode, Identity = Yes, Identity Seed = 1, and Identity Increment= 1.
And then create Dataadapter in design mode, without generating dataset.
I ran the compiler, and it worked fine.
I guess what I did previously was correct but probably messed up in the middle.
Nevertheless, thank you very much Dave. You explained to me how the autonumber works.
|
|
|
|
|
In a M*N Rectangle, i want to Highlight K points .
The K points must be well-distributed.
How to do it ?
|
|
|
|
|
Well, you'll just have to use a well-distributed random number generator to generate coordinate pairs for the points. System.Random should be fine.
|
|
|
|
|
Hi,
I received from a customer an SNMP MIB file for remote a device with TCP/IP.
I looking some help,link or sample for use it.
Best Regards
youssef
|
|
|
|
|
Why did the customer send you this file? What do you want to do with the information it provides?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I received this file for controlling a device and received some alarms.
I received in the same time a serial protocol but it is so slowly for received the all alarms and set some parameters.
I have 50 devices to control !!!! in the same time.
Best regards
youssef
|
|
|
|
|
The MIB file usually get imported into some management application like HP OpenView. It describes to that application what the device is, it's properties, controls, alarms, ...
Are you writing your own management application?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|