After stepping away from this code for a while to do other things. I am back to it and not having much success.
I was able to extract the connection properties from my existing ODBC connection, but each time I try to create a connection file through ArcObjects I am giving the Data Link Properties Form from ArcGIS Desktop.
private static IWorkspaceName CreateODBCconnectionFile()
{
IPropertySet propSet = new PropertySetClass();
propSet.SetProperty("Provider", "SQLNCLI");
propSet.SetProperty("Password", "pwd");
propSet.SetProperty("Persist Security Info", "True");
propSet.SetProperty("User ID", "UID");
propSet.SetProperty("Initial Catalog", "ComDevPrmt");
propSet.SetProperty("Data Source", "server");
IWorkspaceFactory2 pWSFact = (IWorkspaceFactory2)new OLEDBWorkspaceFactoryClass();
propSet.GetAllProperties(out names, out values);
return (IWorkspaceName)pWSFact.Create(@"d:\workspace\", "tmpfile.odc", propSet,0);
}
I have been able to create an .sde file using similar code as shown below.
public static IWorkspaceName CreateConnectionFile(string server, string instance, string user, string password, string database, string version, string SDEdir, string SDEfile)
{
string SDEFullName = SDEdir + SDEfile;
if (File.Exists(SDEFullName))
{
File.Delete(SDEFullName);
}
IPropertySet propertySet = new PropertySetClass();
propertySet.SetProperty("SERVER", server);
propertySet.SetProperty("INSTANCE", instance);
propertySet.SetProperty("DATABASE", database);
propertySet.SetProperty("USER", user);
propertySet.SetProperty("PASSWORD", password);
propertySet.SetProperty("VERSION", version);
IWorkspaceFactory2 workspaceFactory = (IWorkspaceFactory2)new
SdeWorkspaceFactoryClass();
return workspaceFactory.Create(SDEdir, SDEfile, propertySet, 0);
}
Any help is appreciated.
Thanks,
Mele