Solved

Converting Delphi (pascal) to C#

Posted on 2006-07-09
10
809 Views
Last Modified: 2010-05-18
Hi guys

im making a program for restore a MS SQL database remotly. I am trying to catch the infomessage the sql server send but i dont make it. I made same thing in delphi long time ago and have fogotten how i was thinking that time. anyway i still have the code for it in delphi but im vey new in C# and would like someone to translate this delphi code to C# (VS 2005). Thanks guys.

procedure TForm1.ADOConnection1InfoMessage(Connection: TADOConnection;
  const Error: Error; var EventStatus: TEventStatus);


begin



  if error.Description = '10 percent backed up.' then Form1.Progressbar1.StepIt;
  if error.Description = '20 percent backed up.' then Form1.Progressbar1.StepIt;
  if error.Description = '30 percent backed up.' then Form1.Progressbar1.StepIt;
  if error.Description = '40 percent backed up.' then Form1.Progressbar1.StepIt;
  if error.Description = '50 percent backed up.' then Form1.Progressbar1.StepIt;
  if error.Description = '60 percent backed up.' then Form1.Progressbar1.StepIt;
  if error.Description = '70 percent backed up.' then Form1.Progressbar1.StepIt;
  if error.Description = '80 percent backed up.' then Form1.Progressbar1.StepIt;
  if error.Description = '90 percent backed up.' then Form1.Progressbar1.StepIt;
  if error.Description = '100 percent backed up.' then Form1.Progressbar1.StepIt;
end;

I would like to know how to catch them to a memobox also.
0
Comment
Question by:AgdaLon
  • 6
  • 4
10 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17068923
Add a handler to the InfoMessage event:

   SqlConnection conn = new SqlConnection();
   conn.InfoMessage += new SqlInfoMessageEventHandler(InfoMessageSink);

   private void InfoMessageSink(object source, SqlInfoMessageEventArgs e)
  {
  }

Bob
0
 

Author Comment

by:AgdaLon
ID: 17068942
thanks bob... how do i catch it in the procedure?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17068959
I am not sure I understand your question?  Stored procedure?  C# procedure?

Are you asking where to put that code?

Bob
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:AgdaLon
ID: 17068973
I would like to know to catch the info whitch comes bck from SQL server to

private void InfoMessageSink(object source, SqlInfoMessageEventArgs e)
  {

How do i write here

if "error" = then ...

or

memobox.item.add(error);

I have not a clue how to write here....
  }



Thanks for your patiens...

Johan
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 17068989
Johan,

Try this:

private void InfoMessageSink(object source, SqlInfoMessageEventArgs e)
{
   memobox.Items.Add(e.Message);
}

Bob
0
 

Author Comment

by:AgdaLon
ID: 17069018
it works almost ... but i only get 2 percent restored3percent restored6percentrestored
then no more ;(
 i dont find memobox so i used listbox...
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17069025
I guess you mean that a Memo box is a multi-line TextBox control, right?

>>then no more
Are you getting an exception?  Is it completing, just not giving you the right progress?

Bob
0
 

Author Comment

by:AgdaLon
ID: 17069064
it send all progress in one string,.... if i debugg it it comes like this (in one string)

2 percent restored.
4 percent restored.
6 percent restored.
8 percent restored.
10 percent restored.
12 percent restored.
14 percent restored.
16 percent restored.
18 percent restored.
20 percent restored.
22 percent restored.
24 percent restored.
27 percent restored.
29 percent restored.
31 percent restored.
33 percent restored.
35 percent restored.
37 percent restored.
39 percent restored.
41 percent restored.
43 percent restored.
45 percent restored.
47 percent restored.
49 percent restored.
52 percent restored.
54 percent restored.
56 percent restored.
58 percent restored.
60 percent restored.
62 percent restored.
64 percent restored.
66 percent restored.
68 percent restored.
70 percent restored.
72 percent restored.
74 percent restored.
77 percent restored.
79 percent restored.
81 percent restored.
83 percent restored.
85 percent restored.
87 percent restored.
89 percent restored.
91 percent restored.
93 percent restored.
95 percent restored.
97 percent restored.
99 percent restored.
100 percent restored.
Processed 384 pages for database 'Northwind', file 'Northwind' on file 1.
Processed 1 pages for database 'Northwind', file 'Northwind_log' on file 1.
RESTORE DATABASE successfully processed 385

I trried this but it doesnt work ...
if (e.Message=="10 percent restored.")
          listBox1.Items.Add("10 percent restored.");
     if (e.Message=="100 percent restored.")
          listBox1.Items.Add("100 percent restored.");
0
 

Author Comment

by:AgdaLon
ID: 17069257
I found it in MSDN it should look like this to work.... it just need a bit polish now...

thanks for your help mate..

J
0
 

Author Comment

by:AgdaLon
ID: 17069270
forgot the code...

 

private void InfoMessageSink(object source, SqlInfoMessageEventArgs e)
  {
     // listBox1.Items.Add(e.Errors.Count);
             for (int i = 0; i < e.Errors.Count; i++)
    {       listBox1.Items.Add(e.Errors[i].Message);
             }
thanks for your help mate..

J
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question