ArcObjects Library Reference  (GeoDatabase)    

IWorkspaceFactory2 Example

[Visual Basic 6.0]

The following example uses the OpenFromString method to connect to an SDE workspace.

Dim pWorkspaceFactory2 As IWorkspaceFactory2
Set pWorkspaceFactory2 = New SdeWorkspaceFactory
Dim pWorkspace As IWorkspace
Dim strConnect As String
strConnect = "SERVER=cuillin;INSTANCE=esri_sde;USER=scott; _
PASSWORD=tiger;VERSION=SDE.DEFAULT"
Set pWorkspace = pWorkspaceFactory2.OpenFromString(strConnect, 0)

[C#]

    //IWorkspaceFactory2 Example

    //The connection string for a ArcSDE Geodatabase should be in the form of
    //"SERVER=myServer;DATABASE=sde;INSTANCE=5151;USER=Editor;PASSWORD=Editor;VERSION=SDE.DEFAULT"
    public IWorkspace IWorkspaceFactory2_Example(string connectionString)
    {
        IWorkspaceFactory2 workspaceFactory = (IWorkspaceFactory2)new ESRI.ArcGIS.DataSourcesGDB.SdeWorkspaceFactoryClass();
        return workspaceFactory.OpenFromString(connectionString, 0);

        //A better solution is to use IWorkspaceName2::ConnectionString which returns an encrypted password:
        //ENCRYPTED_PASSWORD=0001d2756fc3e1b91529;SERVER=myServer;INSTANCE=5151;USER=Editor;VERSION=SDE.DEFAULT

        //Alternatively, for an OleDB workspace the syntax would be:
        // "CONNECTSTRING=Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=True;Data Source=d:\\my_data\\us_states.mdb";
        //IWorkspaceFactory2 oleDBWorkspaceFactory =
        //        (IWorkspaceFactory2)new ESRI.ArcGIS.DataSourcesOleDB.OLEDBWorkspaceFactoryClass();
        //return oleDBWorkspaceFactory.OpenFromString(connectionString, 0);
    }


[Visual Basic .NET, C++]
No example is available for Visual Basic .NET or C++. To view a Visual Basic 6.0 or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.