Tuesday, July 12, 2011

Connecting To Oracle From ArcObjects Using Oracle Provider For OLEDB

I was trying to connect to oracle from ArcObjects using the Oracle Provider for OLEDB, after some investigation on the subject; I found the correct method.

This function will create the workspace using the Oracle provider
private void connect()
        {
            string cn = "Provider=OraOLEDB.Oracle.1;Password= ;Persist Security Info=True;UserID= ;DataSource=server:port/database"
            IPropertySet pset = new PropertySetClass();
            pset.SetProperty("CONNECTSTRING", cn);
            IWorkspaceFactory fac = new OLEDBWorkspaceFactoryClass();
            fac.Open(pset, 0);           
        } 
 
Don’t forget to initialize the license before you connect.
private void initLic()
        {
            RuntimeManager.Bind(ProductCode.Server);
            IAoInitialize aoInit = new AoInitializeClass();
            aoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcServer);
        }
Hope that was useful

1 comment:

Anonymous said...

thanks.