Solved

Converting Delphi (pascal) to C#

Posted on 2006-07-09
10
811 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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…
Suggested Courses

734 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