HomeActive Query BuilderUsing QueryBuilder to parse SQL statements throws exception.

Using QueryBuilder to parse SQL statements throws exception.


Hi the following code throws NullReference Exception. Am I missing something here ?
I am trying to access QueryStatistics object to get some info about tables and columns used in the query.

try
{
QueryBuilder myqb = new QueryBuilder(true);
myqb.SyntaxProvider = new MSSQLSyntaxProvider();
myqb.SyncSQL = textBox1.Text;
}
catch (System.Exception e)
{
MessageBox.Show(e.Message, "Parsing error");
}

thanks
Tomasz Moska | email
January 30 2009, 08:41 AM
This is known issue. You shouldn't use the SyncSQL property while the Query Builder's form is not visible or the component doesn't have handle yet.
Sergey Smagin | email
21 hours, 12 mins since original post
To validate a query for errors, use the following code:

MSSQLSyntaxProvider syntax = new MSSQLSyntaxProvider();
string errorInfo = "";

if (!syntax.ValidateQuery("select * from Orders", ref errorInfo))
{
MessageBox.Show(errorInfo);
}
Sergey Smagin | email
21 hours, 14 mins since original post
OK but I have the same exception from sample solution "NonVisualDemo" ?!
While pressing QuerryStaistics button ;/ :

public void AnalizeQuery()
{
try
{
// Use 'SyncSQL' property instead of the 'SQL' one.
// The SQL property is asynchronous and works only in visual mode (when the component's handle is created).
qb.SyncSQL = textBox1.Text;

// if you want to hide default database and schema from object names, uncomment lines below
//qb.MetadataContainer.DefaultDatabaseName.AddName("MyDB");
//qb.MetadataContainer.DefaultSchemaNames.AddIdentifier("MySchema");
}
catch (System.Exception e)
{
MessageBox.Show(e.Message, "Parsing error");

return;
}


////
Regarding the handle/ visibility of QueryBuilder control, QueryBuilder has a constructor:

QueryBuilder(bool NonVisualMode)

Do I have to create this control on screen to use some capabilities ...

QueryBuilder myqb = new QueryBuilder(true);
myqb.SyntaxProvider = new MSSQLSyntaxProvider();
myqb.SyncSQL = textBox1.Text;
...
Tomasz Moska | email
2 days, 19 hours since original post
Dear Tomasz,

Please download the updated trial build from the same location. We fixed this bug.
Sergey Smagin | email
2 days, 22 hours since original post
This topic is closed