Hexagon Geospatial
MENU

Developer Discussions

Discuss topics with other Hexagon Geospatial Power Portfolio developers and experts to get the most out of our products.
Showing results for 
Search instead for 
Do you mean 
Reply
Contributor
Posts: 69
Registered: ‎01-14-2018
Accepted Solution

Unable to connect to the database (Text File) in custom command

Hello all,

 

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

Khaled

Technical Evangelist
Posts: 492
Registered: ‎09-11-2015

Re: Unable to connect to the database (Text File) in custom command

Hi Khaled,

 

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.

 

Pavel

Contributor
Posts: 69
Registered: ‎01-14-2018

Re: Unable to connect to the database (Text File) in custom command

Thanks Pavel,

 

As you see in the below snapshot, the only property available for the ConnectInfo of my connection is Length

 

 

Thanks 

KhaledConnectInfo.png

Technical Evangelist
Posts: 492
Registered: ‎09-11-2015

Re: Unable to connect to the database (Text File) in custom command

Hi Khaled,

 

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"

 

Pavel

Contributor
Posts: 69
Registered: ‎01-14-2018

Re: Unable to connect to the database (Text File) in custom command

Thanks @pkrejcir for your clarificiation,

 

I already have the attached pdf for the Geomedia Object Reference but it seems to be an old version,

Could you kindly share the link to the latest reference.

Note: I am using Geomedia version 16 build 20059.

 

Thanks

Khaled

Technical Evangelist
Posts: 838
Registered: ‎09-11-2015

Re: Unable to connect to the database (Text File) in custom command

Hi Khaled,

 

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.

 

Regards,

Jan

Jan Neumann
Post Sales Engineer Web Applications
Hexagon Geospatial

Contributor
Posts: 69
Registered: ‎01-14-2018

Re: Unable to connect to the database (Text File) in custom command

Hi all,

 

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

Khaled

Technical Evangelist
Posts: 838
Registered: ‎09-11-2015

Re: Unable to connect to the database (Text File) in custom command

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").

 

Jan

Jan Neumann
Post Sales Engineer Web Applications
Hexagon Geospatial

Technical Evangelist
Posts: 492
Registered: ‎09-11-2015

Re: Unable to connect to the database (Text File) in custom command

Hi Khaled,

 

just to add to what Jan wrote, the Mode must be 0. There is no write access to text files.

 

Pavel

Highlighted
Contributor
Posts: 69
Registered: ‎01-14-2018

Re: Unable to connect to the database (Text File) in custom command

Hi @pkrejcir and @jan.neumann,

I really appreciate your help, that worked for me when I made the mode = 0.

 

Best Regards,Smiley Wink

Khaled

Do you need immediate support?
Please submit a Ticket through our
Development Ticket Portal.