Desktop productivity for business analysts and programmers

Pulling SAS error message while executing Query from C#

Reply
Super Contributor
Posts: 400

Pulling SAS error message while executing Query from C#

My application allows users to change data in a grid and update the values within my sas data tables. That part works correctly. What I need to know is how to capture an error that sas throws and return it to my windows application and display it?
Community Manager
Posts: 2,887

Re: Pulling SAS error message while executing Query from C#

What's the context here? Is this a custom task within EG or just a Windows app that you created with .NET?

If you are using the IOM LanguageService to issue a query (PROC SQL UPDATE), you would need to use the FlushLog or FlushLogLines call to get the SAS log, which would contain any errors/warning along with the rest of the SAS log.

If this is a custom task, there are are some wrapper classes that I can point you to. If that's the case, then we need to know whether this is EG 4.1 or 4.2.

Chris
Super Contributor
Posts: 400

Re: Pulling SAS error message while executing Query from C#

Chris,
Thank you so much for your response.

It is a windows forms "C#" app. I sending regular sql statements to SAS/Share server using OleDB. This is a sample of the updates I pass in.

"update system.user set UserNumber = '001' where ID = 1 and PRJID = 11"

Lets assume that UserNumber has a unique key constraint and that someone else already has '001'. I need to get the sas error message because it tells me what table and what constraint was violated.

Any help pointing me in the right direction would be appreciated.

Thank You
Community Manager
Posts: 2,887

Re: Pulling SAS error message while executing Query from C#

Jerry,

I see. You are manipulating the data via the provider, not with IOM and Language Service.

You probably already know about these resources:

The SAS OLE DB "cookbook":
http://support.sas.com/documentation/tools/oledb/index.htm

Handling Error Objects:
http://support.sas.com/documentation/tools/oledb/app_error_objects.htm

Chris
Super Contributor
Posts: 400

Re: Pulling SAS error message while executing Query from C#

Chris,
Would it be more advantages to use IOM? I'm not too familier with it but if it can speed up my app talking to SAS/Share server then I can look into it.

Have you used it? What are you thoughts on it, if you don't mind?

Thanks again
Community Manager
Posts: 2,887

Re: Pulling SAS error message while executing Query from C#

First, IOM requires that you have SAS Integration Technologies on your server. So if you have that, it's a good start.

IOM offers the LanguageService interface to allow you to run SAS programs and gather the logs and results. You can also access data like you do now, but using the SAS IOM OLE DB provider.

If all you need to do is treat your SAS/Share server like a database, then your current approach is probably fine. Are you using ADO or ADO.NET? And do you have a more complete C# example for how you are working with this? That would help our experts here to give advice.

This isn't exactly the correct forum for this, but I know there probably isn't another that is a better fit.

Chris
Super Contributor
Posts: 400

Re: Pulling SAS error message while executing Query from C#

Chris,
That is pretty much all I need to is treat sas/share like a database.

Here is an example of how i'm using it:

using System.Data.OleDb;

string conn = "Provider=sas.ShareProvider.1;Data Source=Share1;Location=server1;Mode=Read|Share Deny None";

OleDbConnection connSAS = new OleDbConnection(conn);
connSAS.Open();

OleDbCommand sasCommand = connSAS.CreateCommand();
sasCommand.CommandType = CommandType.Text;

sasCommand.CommandText = "update system.temp set fname='bob' where id = 10";

try
{
sasCommand.ExecuteNonQuery();
}
catch (System.Exception exc)
{
MessageBox.Show(exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

Is it possible from what i'm doing to get the exact error back from SAS or do I have to take a different approach?

Thanks for your help that is a big problem for me and your help is appreciated.

Jerry
Super Contributor
Posts: 400

Re: Pulling SAS error message while executing Query from C#

Can anyone else help?
Super Contributor
Posts: 400

Re: Pulling SAS error message while executing Query from C#

Can anyone please just point me in the right direction?
I just want to know how to pull the sas error message to my C# application using oledb to run my sql.

Thank You
Occasional Contributor
Posts: 5

Re: Pulling SAS error message while executing Query from C#

Hello,

I am having the same problem and wonder if it is possible to create/modify SAS dataset this way.

If you already figure out a way, please post your solution.

Thank you,
Ken
Ask a Question
Discussion stats
  • 9 replies
  • 226 views
  • 0 likes
  • 3 in conversation