Author Topic: Connectionstring  (Read 11435 times)

utkarsh

  • EA User
  • **
  • Posts: 38
  • Karma: +0/-0
    • View Profile
Connectionstring
« on: September 08, 2008, 09:06:42 pm »
Hi,

How can I retreive connectionstring of the repository? I am using repository.Connectionstring but if we open it through file we get the file name. I want to retrieve the connection string which is used to connect to the DB. I need it to open a connection to DB through my addin.
Please help.
Thanks

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Connectionstring
« Reply #1 on: September 09, 2008, 01:24:44 am »
I gather you mean you need a connection string for an EAP file.

One way to get what you need would be to open your EAP file as if it were a DBMS repository. Go through the same steps by hand as you would to open a DBMS project, but specify the MS Access driver (I think you can use either ODBC or OLEDB). The following dialogs will allow you to point to the database file.

When you've opened the project, try a Save As operation, pointing to a new file. That file should contain the connection string, which you can retrieve with a text editor. Or, you could query the repository as you've done before - you should now get the connection string - and save the result someplace.

You could also build the string yourself. Remember to include the prefix string that EA builds for you. Use the MS Jet 3.51 or 4.0 driver - the one that matches your Tools | Options setting - for ODBC or OLEDB as appropriate for your environment.

HTH, David
No, you can't have it!

utkarsh

  • EA User
  • **
  • Posts: 38
  • Karma: +0/-0
    • View Profile
Re: Connectionstring
« Reply #2 on: September 09, 2008, 02:43:26 pm »
Sorry, I think I was not clear enough.

I want to get the connection string in the C# code in my addin.
I am using Repository.ConnectionString which is exposed by API but the problem is it return the file name if we open the .EAP file.

I want to retrieve the connection string to open a sql connection to DB in my code. For achieving that I need server name, user credentials etc for connecting the DB of the .EAP file.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Connectionstring
« Reply #3 on: September 09, 2008, 11:35:25 pm »
You will have to create the string explicitly in your code.

Follow the procedure I outlined and you'll see what EA uses when it opens an EAP file as a repository - you really can do that - and then use the same provider, options, and such. It really does work.

David
No, you can't have it!

utkarsh

  • EA User
  • **
  • Posts: 38
  • Karma: +0/-0
    • View Profile
Re: Connectionstring
« Reply #4 on: September 10, 2008, 02:58:18 am »
Thanks David.

I can check the connection string in the .EAP file but how can I get using the API. I need to get in code. Repository.Connectionstring do not gives connection string everytime. When it return filename how can i get the actual connection string.

thanks for the help.

utkarsh

  • EA User
  • **
  • Posts: 38
  • Karma: +0/-0
    • View Profile
Re: Connectionstring
« Reply #5 on: September 10, 2008, 03:02:18 am »
Just wanted to add to my last reply. I want to know server name, DB name, user, password using API when Repository.Connectionstring returns me file name in C#.

Thanks :)


«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Connectionstring
« Reply #6 on: September 10, 2008, 03:21:36 am »
Once again, see my first answer. When you have done the Save As operation, EA will save a text file - with an EAP extension - that contains a connection string. Practice this with a DBMS repository if you want, then go through the same process to open an 'ordinary' EAP project.

Hint: Do this after opening the EA application without first opening a project. Follow the directions in EA help.
No, you can't have it!

Eric Johannsen

  • EA User
  • **
  • Posts: 43
  • Karma: +0/-0
  • Model Driven Business[ch0174]
    • View Profile
Re: Connectionstring
« Reply #7 on: September 11, 2008, 09:57:36 am »
Just to try and take a different angle at answering this...

There are two kinds of repositories for EA.

1. EAP files
2. Server-type SQL database (SQL Server, Oracle, ...)

If the connection string is coming back as an EAP file name, the repository is just an Access database, not a server-type SQL database.  EAP files / Access databases do not HAVE a server name, they are just a file on either the local machine or a network share.

What Midnight is saying is that you can build your own connection string, by hand, using the EAP file name that Repository.ConnectionString returns to you, using the MS-Access drivers.

Here's a link showing you how to format the connection string:

http://www.connectionstrings.com/?carrier=access

The "Dbq=" part of the connection string is the file name of the EAP file.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8085
  • Karma: +118/-20
    • View Profile
Re: Connectionstring
« Reply #8 on: September 11, 2008, 11:49:39 am »
An alternative interpretation of the original question is that he's opening his DBMS database through an eap shortcut file, and the connectionstring parameter reports that.

In order to get the actual connection string you would need to look at the file.  Also note that if a user has connected using an encrypted connection string you will get the connection string in an encrypted form.

utkarsh

  • EA User
  • **
  • Posts: 38
  • Karma: +0/-0
    • View Profile
Re: Connectionstring
« Reply #9 on: September 12, 2008, 01:53:55 am »
Exactly Simon, this is the case I want to handle.
The problem is i can not look at the file. I should retrieve it dynamically in my addin. I am using C#.
Repository.Connectionstring returns me the file name in the case you mentioned. How can get the connection string using EA API.

Thanks for the help.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8085
  • Karma: +118/-20
    • View Profile
Re: Connectionstring
« Reply #10 on: September 12, 2008, 08:19:11 am »
I don't think you can't get it from the EA API.  That's why I said you'd have to look at the file.

utkarsh

  • EA User
  • **
  • Posts: 38
  • Karma: +0/-0
    • View Profile
Re: Connectionstring
« Reply #11 on: September 15, 2008, 03:35:08 pm »
Thanks Simon.

I could not get connection string from the API in case it is shortcut to the server, but i read the file from addin using c# and it worked :)

No issues till the connection string is not encrypted, but I again ran into problem if the connection string is encrypted. Is there any method available in the API using which i can decrypt the connection string?

Thanks once again.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8085
  • Karma: +118/-20
    • View Profile
Re: Connectionstring
« Reply #12 on: September 15, 2008, 04:10:42 pm »
No, the connection string encryption is to prevent users from knowing the actual encryption string to the database (as required by some companies).  If an add-in could get the unencrypted string then the whole thing would be unsuitable for the customers who wanted it.

If your addin requires the connection string, it will have to be documented as a restriction to your add-in that it doesn't work with an encrypted connection string.

utkarsh

  • EA User
  • **
  • Posts: 38
  • Karma: +0/-0
    • View Profile
Re: Connectionstring
« Reply #13 on: September 15, 2008, 04:27:31 pm »
Thanks Simon.