Solved

Converting Delphi (pascal) to C#

Posted on 2006-07-09
10
813 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

617 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