v
Not logged inv
SearchAsk a QuestionReport an IssueMake a SuggestionMy Questions and Issues
KB Article
Find By ID

How to log the SQL queries made by XPO

Article Details

A2572
1, 6.x, 7.x
10/25/2011
.NET
eXpress Persistent Objects

Is it possible to see the queries generated and executed by XPO?

Solution

Yes, you can see the XPO database queries and their execution results in the Output window when debugging your project in Visual Studio. For this, please add the following lines to the App.Config file of your project:

[XML]

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

    <system.diagnostics>

        <switches>

            <add name="XPO" value="3" />

        </switches>

    </system.diagnostics>

</configuration>

If your project does not include such a file, please add it via the Project | Add New Item... menu command:

If you wish to output XPO SQL commands in a text file, please write the following code in your application's configuration file. XPO will create a trace.log file with queries in the application directory.

[XML]

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

    <system.diagnostics>

        <trace autoflush="true" indentsize="4">

            <listeners>

                <add name="LogFileTraceListener" type="System.Diagnostics.TextWriterTraceListener"

                    initializeData="trace.log" />

                <remove name="Default" />

            </listeners>

        </trace>

        <switches>

            <add name="XPO" value="3" />

        </switches>

    </system.diagnostics>

</configuration>

As you can see, XPO utilizes the standard System.Diagnostics trace logging mechanism. Thus, you can create your own TraceListener class, which logs queries in a database or in a text box, for example.

[C#]

System.Diagnostics.Trace.Listeners.Add(new MyTraceListner(textBox1));

...

class MyTraceListner : System.Diagnostics.TraceListener {

    TextBox outputWindow;

    public MyTraceListner(TextBox outputWindow) {

        this.outputWindow = outputWindow;

    }

    public override void Write(string message) {

        outputWindow.AppendText(message);

    }

    public override void WriteLine(string message) {

        outputWindow.AppendText(message + "\r\n");

    }

}

The additional information on this can be found in the MSDN Library:
TraceListener Class

Attachments

Do you have any comments? We are eager to hear them!

Average rating: 7.93 out of 9
15 people have rated this page
 
 
 
1
2
3
4
5
6
7
8
9
 
Post Your Vote (Login Required)
v
v
Search
Searching Tips