BookmarkSubscribeRSS Feed
qkaiwei
Calcite | Level 5

obSAS2 = obSAS.GetNewWorkspace();

sasDbConn2 = new OleDbConnection();

sasDbConn2.ConnectionString = "provider=sas.iomprovider.1; SAS Workspace ID=" + obSAS2.UniqueIdentifier;

sasDbConn2.Open();

I'll create colocated workspaces for parallel processing, but when compiling codes and reaching the line to open an OleDbConnection, visual studio throws an exception showing:

The object 2C2A3465-99AF-4C56-8653-B5D5CCED59BF could not be found; make sure it was previously added to the object keeper.

Does anyone once meet the problem?

5 REPLIES 5
AndreasMenrath
Pyrite | Level 9

you need to register your SAS workspace to the so called "object keeper" first.

You find an example here: http://savian.blogspot.com/2011/04/this-one-is-real-keeper.html

qkaiwei
Calcite | Level 5

Thank you, your post is very helpful. but there is another question.

You kwow, the purpose I create obSAS2 is to perform background processing and the user need not to face frozen UI and wait for a long time before the result coming out.

See the following codes, expecially the line with comments,

sasDbAdap.Fill(srcTable);

I don't why there is a NullReferenceException thrown, do you have experience of using obSAS with BackgroundWorker?

At last, If try to close obSAS2, is my way OK or not?

    obOK.RemoveObject(obSAS2);

    obSAS2.Close();  

/*----------------------------------------------------------------------------------------------------------------------*/

private void bgWorker_DoWork(object sender, DoWorkEventArgs e) {
    bgSuccess = true;

    if (obSAS2 == null || obSAS2.UniqueIdentifier.Length == 0) {
        obSAS2 = obSAS.GetNewWorkspace();
        SasServerCount++;
        obOK.AddObject(SasServerCount, SasServerCount+":SASBK", obSAS2);

    /*Stored Process Execution*/

        sasDbConn2 = new OleDbConnection();
        sasDbConn2.ConnectionString = "provider=sas.iomprovider.9.2; SAS Workspace ID=" + obSAS2.UniqueIdentifier;
        sasDbConn2.Open();
    }
}

void obSASLang2_StepError() {
    bgSuccess = false;
}

private void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
    OleDbDataAdapter sasDbAdap = new OleDbDataAdapter("select * from sashelp.class", sasDbConn);
    try {
        sasDbAdap.Fill(srcTable);  /*Error: NullReferenceException*/
    } catch (Exception ex) {
        bgSuccess = false;
    }
    if (bgSuccess)
      this.grd.DataSource = srcTable;
     
    /*Close obSAS2*/
    obOK.RemoveObject(obSAS2);
    obSAS2.Close();  
}

AndreasMenrath
Pyrite | Level 9

I don't understand why you need a second SAS session just to prevent your UI from freezing?

If you use a backgroundworker (msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx) with your primary SAS Session to execute your SAS Code and write the results to a dataset in the backgroundworker thread you don't need a second SAS session.

qkaiwei
Calcite | Level 5

First, thank you for your reply.

I use 1 or more background SAS session before I want to run two or more job asychronously, for example, a ETL job and Forecast job at the same time.

I have found the reason: the DoWork method is in the background session, and the RunWorkerCompleted in the foreground session, so if I create obSAS2, get OleDbconnection2, run sas codes only in the same sesion, that's will be OK. I have tested it in my EG Add-in for several days, there is no problem, at last until today.

Although SAS open a door to enhance EG by development of Add-in,  there are still too few materials about the development, so another question.

SAS.Tasks.Toolkit.SasServer obServer;
try {
   obServer = new SAS.Tasks.Toolkit.SasServer( consumer.AssignedServer);

}......

How to get SAS workspace from the obServer, I know I can get SAS workspace from "consumer", but if connection between server and EG is broken, I must re-connect manually by hands, now I try to do it by codes.

I find the method SAS.Tasks.Toolkit.SasServer.GetWorkspaceIdentifier()

Remarks

This method will force a connection to the SAS server, if the connection does not yet exist. The connection might cause a slight delay. It might also force a prompt for user ID and password, depending upon the configuration of the server and its metadata.

ChrisHemedinger
Community Manager

You're correct.  The API doesn't connect all of the dots in this case.

You can get the WorkspaceIdentifier, which exists only if you are already connected to a session.  That will give you the workspace ID for the session that EG knows about (not any second session you might have spawned using code from your previous post).

But you cannot get the IWorkspace handle from the SasServer class.  Given the workspace ID, you can probably find it using the ObjectKeeper route.

You can get the IWorkspace from the ISASTaskConsumer, given the server name.  But that will throw the logic back into EG to connect to a server as well, if you haven't already got a connection.  Again, it's the one-and-only SAS workspace connection (per logical server) that EG will manage for you.

Chris

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1337 views
  • 0 likes
  • 3 in conversation