开发者

Reading data from a SAS data source in .Net

I've been asked to read some data from SAS in an ASP.Net application. I've got working code for a Windows Forms app. However the same code doesn't work in ASP.Net however I can try it. A clean project with the same references consistently fails.

Here's what I've got for the connection:

    SASWorkspaceManager.WorkspaceManager oWorkspaceManager
        = new SASWorkspaceManager.WorkspaceManager();
    string xmlInfo = "";

    SASWorkspaceManager.ServerDef oServerDef = new SASWorkspaceManager.ServerDef();
    oServerDef.MachineDNSName = "server";
    oServerDef.Protocol = SASWorkspaceManager.Protocols.ProtocolBridge;
    oServerDef.Port = <port>;
    oServerDef.BridgeEncryptionAlgorithm = "SASProprietary";
    oServerDef.BridgeEncryptionLevel = 
        SASWorkspaceManager.EncryptionLevels.EncryptUserAndPassword;

    SAS.Workspace oSASWorkspace = 
        oWorkspaceManager.Workspaces.CreateWorkspaceByServer ("", 
        SASWorkspaceManager.Visibility.VisibilityProcess, oServerDef, "user",
        "pass", out xmlInfo);

    oSASWorkspace.LanguageService.Submit(
        "proc means data = sashelp.class;output out=meanout;run;");
    OleDbDataAdapter oOleDbDataAdapter = new OleDbDataAdapter
                            ("select * from work.meanout",
        "provider=sas.iomprovider.1; SAS Workspace ID=" + 
        oSASWorkspace.UniqueIdentifier);
    DataSet oDS = new DataSet();
    oOleDbDataAdapter.Fill(oDS, "sasdata");

    oWorkspaceManager.Workspaces.RemoveWorkspaceByUUID(
        oSASWorkspace.UniqueIdentifier);
    oSASWorkspace.Close();

With just that it fails initialising the data adapter with an inner exception of "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." If I add Trust=Full to the web.config file I get the same error directly when filling the data adapter. We can prove that executing the SAS command via the workspace manager is working, it's when we then try to read the results back that it fails when initialising the connection to SAS. For whatever reason, the fragment

OleDbDataAdapter oOleDbDataAdapter = new OleDbDataAdapter
                        (<Read Command>,
    "provider=sas.iomprovider.1; SAS Workspace ID=" + 
    oSASWorkspace.UniqueIdentifier);

which seems to be cited everywhere as how to do it just keeps raising an error when run through ASP.Net.

I'm guessing it's a user pe开发者_StackOverflow中文版rmissions issue somewhere with it not liking running under the IIS user but wouldn't know what needs permissions granted to it. Some SAS documentations somewhere or other (sorry, can't find it) suggested making sure the user had permissions, but the ASPNET user does have full access to the whole SAS program directory on the dev machine. Does anyone know what else I might need to set? Thanks.


What version of SAS are you using? Starting with 9.13, WorkspaceManager is deprecated in favor of ObjectManagerMulti (or ObjectManagerMulti2 in 9.2). I'm not sure this would solve your error though.


Is the asp server on another machine. If so, and possibly anyway, you will need to license SAS Integration Technologies. See the online documentation for gory details.


I ran into a couple of issues when running something similar in IIS. First, you'll have to adjust the permissions on the SAS Workspace component in admin tools -> component services. You'll have to add permissions for the user that your application pool is running under. This will be under the properties windows of the component -> security tab -> launch and activation permissions, and also the access permissions.

I also ended up having to modify the SASUSER directory in the config because network service didn't have access.

C:\Program Files\SASHome\SASFoundation\9.3\nls\en\sasv9.cfg

/*-SASUSER "?CSIDL_PERSONAL\My SAS Files\9.3" */ -SASUSER "c:\sasuser"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜