0

Im working in c#, I'm using mysql .net connector to interact with a remote mysql db. Is it safe to include the connection string inside the code and work with the db directly through the command object or should I be posting to a php middle layer to hide the connection string?

Thanks in advance.

2 Answers 2

2

In my opinion:

  1. You shouldn't put Your connection string directly in Your C# code if Your application could be decompiled = I mean WinForms application.

  2. If You are working on a Windows application, then try to implement a log-in window. Where user will pass his/her user name and password. This solution needs a mysql user or users for every person that would have access to the system.

  3. If Your are working on a web application, then put You connection string inside web.config file.

  4. If You are working on application with unrestricted access, then I think You should implement some layer... but remember, never pass SQL queries as plain text via network, as someone could sniff it. I would recommend some kind of webservice.

Sign up to request clarification or add additional context in comments.

2 Comments

its a winform application.. 1 part of my app implements a mysql message cue where queries to the database are made frequently, say ever 2 seconds, would the php layer slow this down would you say?
I would say, security first! As in everyday life.... every agent/broker/intermediary increases costs (time in this case). If Your query executes fast (faster then 2 seconds) then I think it's fine - maybe some kind of queue or semaphore should be implemented.
1

Then the connection string is just stored in the PHP middleware layer, so what's the difference? It has to be stored somewhere.

I would keep it simple and store it in the app.config or web.config of the C# app your writing.

Couple notes about storing it: - Production connection strings should not be stored in version control. - A production configuration file should exist on the production servers with the connection string. - For added security, you can encrypt your connection string (http://msdn.microsoft.com/en-us/library/89211k9b(v=vs.80).aspx)

1 Comment

the difference is that the connectionstring will always be invisible since the php code is not public(?) from what I can reason any http analyzer could grab the connection string as its sent out from a to b, or is that incorrect?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.