Before performing the join operation, check that the database can be connected.
Try
{
// Use oledb to connect to the database and the SYS. Basic information table
Iworkspacefactory pworkspacefactory = new oledbworkspacefactory ();
Ipropertyset ppropset = new propertyset ();
Ppropset. setproperty ("connectstring", "provider = sqloledb; Data Source =" + this. instancebox. text + "; initial catalog = sys; user id = sa; Password = sa ;");
Iworkspace pworkspace = pworkspacefactory. Open (ppropset, 0 );
Ifeatureworkspace pfeatureworkspace = (ifeatureworkspace) pworkspace;
Itable pforeigntable = pfeatureworkspace. OpenTable ("SYS. Basic info table ");
// Open temp. mxd that has fixed the data source
Imapdocument pmapdocument = new mapdocumentclass ();
Pmapdocument. Open (startpath + @ "/temp. mxd", null );
IMAP pmap = pmapdocument. get_map (0 );
// Obtain the Layer
Ilayer player = NULL;
For (INT I = 0; I <pmap. layercount; I ++)
{
If (pmap. get_layer (I). Name = "point ")
{
Player = pmap. get_layer (I );
}
}
If (player = NULL)
{
MessageBox. Show ("opening the map file (. mxd) failed ");
Return;
}
// Join
Ifeaturelayer pflayer = (ifeaturelayer) player;
Ifeatureclass pfclass2 = pflayer. featureclass;
Imemoryrelationshipclassfactory pmemrelclassfactory = new memoryrelationshipclassfactoryclass ();
Irelationshipclass prelaclass = pmemrelclassfactory. open ("tablejoin1", pfclass2, "Point Number", (iobjectclass) pforeigntable, "Point Number", "forward", "backward", esrirelcardinality. esrirelcardinalityonetoone );
Idisplayrelationshipclass pdisplayrelationshipc = (idisplayrelationshipclass) pflayer;
Pdisplayrelationshipc. displayrelationshipclass (prelaclass, esrijointype. esrileftouterjoin );
Pmapdocument. Save (false, true );
Pmapdocument. Close ();
}
Catch (system. Exception ex4)
{
MessageBox. Show (ex4.message );
Return;
}