Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Converting Delphi (pascal) to C#

Posted on 2006-07-09
10
Medium Priority
?
818 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
Independent Software Vendors: 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 1500 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

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.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month13 days, 11 hours left to enroll

963 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