我使用SAS Integration Technologies COM组件从C#.NET项目连接到SAS服务器。我想将语句提交给SAS工作区,然后使用OLE DB提供程序(SAS.IOMProvider)从SAS加载输出数据集。我可以使用这样的代码成功完成此操作:
static int Main(string[] args)
{
var keeper = new ObjectKeeper();
var factory = new ObjectFactoryMulti2();
var server = new ServerDef()
{
MachineDNSName = "sas.server.com",
Protocol = Protocols.ProtocolBridge,
Port = 8591,
BridgeSecurityPackage = "Negotiate",
};
var workspace = (IWorkspace)factory.CreateObjectByServer("Workspace1", true, server, null, null);
keeper.AddObject(1, workspace.UniqueIdentifier, workspace);
try
{
using (var conn = new OleDbConnection("Provider=SAS.IOMProvider.1; Data Source=iom-id://" + workspace.UniqueIdentifier))
{
// success
conn.Open();
}
}
catch (Exception ex)
{
System.Console.Error.WriteLine(ex.ToString());
return 1;
}
finally
{
keeper.RemoveObject(workspace);
workspace.Close();
}
return 0;
}
但是,当我尝试使用ObjectPool
的{{1}}功能时,OLE DB连接不起作用。它总是抛出"无法找到物体;确保它之前已添加到对象管理器中。"以下代码不起作用:
ObjectFactoryMulti2
有没有办法在SAS OLE DB提供程序中使用SAS连接池?
答案 0 :(得分:1)
SAS支持部门对此问题给出了一个很好的答案。使用连接池时,您必须将工作区强制转换为IServerStatus
并使用其ServerStatusUniqueID
属性而不是IWorkspace.UniqueIdentifier
进行连接。
var pool = factory.ObjectPools.CreatePoolByServer("Pool1", server, login);
var lease = pool.GetPooledObject(null, null, 5000);
var workspace = (IWorkspace)lease.SASObject;
var status = (IServerStatus)lease.SASObject;
keeper.AddObject(1, workspace.UniqueIdentifier, workspace);
using (var conn = new OleDbConnection("Provider=SAS.IOMProvider.1; Data Source=iom-id://" + status.ServerStatusUniqueID))
{
// success
conn.Open();
}
keeper.RemoveObject(workspace);
lease.ReturnToPool();