Book a Demo

Author Topic: Identifying a Project's Database  (Read 4820 times)

crd

  • EA User
  • **
  • Posts: 34
  • Karma: +0/-0
    • View Profile
Identifying a Project's Database
« on: May 28, 2010, 02:36:49 am »
Using the EA API, is there an easy way to identify the project's database?  In my code I need to be able to identify whether or not I am running against an EAP, Oracle Database or SQL Server project.  

I am currently checking the last 3 characters of the connection string to identify the EAP.  I find this through the App.Repository.ConnectionString.  

Am I missing something obvious?

Thanks for you help!
Carol

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Identifying a Project's Database
« Reply #1 on: May 28, 2010, 10:53:04 am »
I check for the string: "Provider=" in the connection string - this tells you if you have a Server connection (if found) or a file based access...

NOTICE I said file based access...  What you probably haven't come across yet is that EA allows you to create shortcut files ALSO with the file extension .EAP. ::)   These aren't MS Access DBs but text files including a provider field.  (You can create one by File|Save Project As... and selecting (*) Shortcut)

You need to try to open the .EAP file and if it throws an exception, then investigate the first line and see if it starts with: "EAConnectString:" and regenerate a connection string from that...

HTH,
Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Identifying a Project's Database
« Reply #2 on: May 28, 2010, 04:21:01 pm »
Whenever I need to find out if an eap file is really a shortcut file or an access database I check on the size.
The shortcut files are typically just a few hundred bytes, where an ms-access eap file is at least 2 MB.

Saves you from trying to read the ms-access file as a textfile.

Geert

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Identifying a Project's Database
« Reply #3 on: May 28, 2010, 04:24:24 pm »
Also, the type of the database is stored in the
"DBType=X" part.
I know that "DBType=1" stands for MS-SQL Server, but I don't know about the other databases.
This DBType is independent of the actual driver you use to connect to the database, which is given in the "Provider" part.

Geert

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: Identifying a Project's Database
« Reply #4 on: May 28, 2010, 04:46:41 pm »
Quote
I know that "DBType=1" stands for MS-SQL Server, but I don't know about the other databases.
0 = MySQL
1 = MS SQL Server
2 = JET
3 = Oracle
4 = PostgreSQL
5 = Adaptive Server Anywhere
7 = Progress OpenEdge
8 = Access 2007
The Sparx Team
[email protected]

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Identifying a Project's Database
« Reply #5 on: May 28, 2010, 06:20:02 pm »
Quote
Quote
I know that "DBType=1" stands for MS-SQL Server, but I don't know about the other databases.
[size=18]...[/size]
2 = JET
[size=18]...[/size]
Hi Neil,

Can you confirm that's JET used in "Server" mode (Access 2007 can only be connected in Server Mode)

We still have to test the .EAP file to see if it's a shortcut or not don't we?

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!