从 .Net 中的 SAS 数据源读取数据

发布于 2024-08-17 12:31:20 字数 2039 浏览 5 评论 0原文

我被要求在 ASP.Net 应用程序中从 SAS 读取一些数据。我有 Windows 窗体应用程序的工作代码。然而,相同的代码在 ASP.Net 中无法工作,但我可以尝试一下。具有相同引用的干净项目始终会失败。

这是我获得的连接信息:

    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();

仅此而已,它无法初始化数据适配器,并出现内部异常 “尝试读取或写入受保护的内存。这通常表明其他内存已损坏。”如果我将 Trust=Full 添加到 web.config 文件中,则在填充数据适配器时会直接收到相同的错误。我们可以证明通过工作区管理器执行 SAS 命令是有效的,但当我们尝试读回结果时,初始化 SAS 连接时失败了。无论出于何种原因,似乎到处都引用了如何执行此操作的片段

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

在通过 ASP.Net 运行时不断引发错误。

我猜这是某个用户权限问题,它不喜欢在 IIS 用户下运行,但不知道什么需要授予它权限。某些 SAS 文档(抱歉,找不到)建议确保用户拥有权限,但 ASPNET 用户确实拥有对开发计算机上整个 SAS 程序目录的完全访问权限。有谁知道我还需要设置什么?谢谢。

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 permissions 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

放我走吧 2024-08-24 12:31:20

您使用什么版本的 SAS?从 9.13 开始,WorkspaceManager 已被弃用,取而代之的是 ObjectManagerMulti(或 9.2 中的 ObjectManagerMulti2)。我不确定这会解决你的错误。

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.

羞稚 2024-08-24 12:31:20

是asp服务器在另一台机器上。如果是这样,并且可能无论如何,您将需要获得 SAS Integration Technologies 的许可。有关详细信息,请参阅在线文档。

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.

不语却知心 2024-08-24 12:31:20

我在 IIS 中运行类似的东西时遇到了一些问题。首先,您必须在管理工具 -> 中调整 SAS 工作区组件的权限。组件服务。您必须为运行应用程序池的用户添加权限。这将位于组件的属性窗口下 ->安全选项卡 ->启动和激活权限,以及访问权限。

我最终还必须修改配置中的 SASUSER 目录,因为网络服务无权访问。

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

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

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"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文