01-21-2018 12:41 AM
I am trying to make a custom command that connect to a text-file using c#, but when clicking on the command in GeoMedia it keeps giving me an error "Unable to connect to the database. Please verify that your warehouse-connection parameters are correct and try again."
I am using the below code:
PClient.Connection pClientConnection1 = new PClient.Connection(); pClientConnection1.Type = "TextFile.GDataBase"; pClientConnection1.Name = "Text File Connection 1"; pClientConnection1.Location = @"C:\Users\A\Desktop\SDRFiles\AG617394d26.PNT"; pClientConnection1.Connect();
Also what to write if I want to add the coordinate system?
Thanks in advance
Solved! Go to Solution.
01-22-2018 12:31 AM
the TextFile connection requires the ConnectInfo property to be set, it contains the file location and also the tfd (text file definition) file location, which is mandatory for that format. On the other hand, the Location property should be set, but it is ignored.
01-22-2018 12:50 AM
As you see in the below snapshot, the only property available for the ConnectInfo of my connection is Length
01-22-2018 02:07 AM
ConnectInfo is a string type property, just like Location. So you should have something like this in your code:
pClientConnection1.Location = "Whatever"
pClientConnection1.ConnectInfo =@"Look at the GeoMedia Object Reference for what should be in this string"
01-22-2018 03:21 AM
01-22-2018 03:39 AM
That is not a GeoMedia object reference documentation. Documentation is delivered with GeoMedia product and should be available in Start menu under Hexagon GeoMedia Desktop 2016 > Developer Documentation > GeoMedia Object Reference.
01-22-2018 04:38 AM
I really appreciate your help,
I opened the geomedia objects reference and I tried the below code to import a text file:
PClient.Connection pClientConnection1 = new PClient.Connection(); pClientConnection1.Type = "TextFile.GDatabase"; pClientConnection1.Name = "Text File Connection 1"; pClientConnection1.Location = "SomeName"; pClientConnection1.ConnectInfo = pClientConnection1.ConnectInfo = @"DATA=C:\Users\A\Desktop\SDRFiles\AG617394d26.PNT;FORMAT=C:\Users\A\Desktop\SDRFiles\TFDPNT.tfd;CSF=C:\Users\A\Desktop\SDRFiles\EgyptRedBelt.csf"; pClientConnection1.Mode = 1; pClientConnection1.Connect();
but it gives me the below error message:
"Unable to connect to the database. Please verify that your warehouse-connection parameters are correct and try again."
Thanks a lot
01-22-2018 04:48 AM
Are you sure you pasted the code correctly here? This line seems weird:
pClientConnection1.ConnectInfo = pClientConnection1.ConnectInfo = ...
Are you able to connect to the Text File using GeoMedia GUI?
You also shouldn't instantiate GM objects using new operator within a custom command. Please rather use gobjGeoApp object (Application class instance) and its method CreateService("GeoMedia.Connection").