Say you've started an open source project and are posting it on a public repository. (like I have, using Codeplex.)

One of the key files just makes the connection to the database, contains the login/password, and is just included from any other source file that needs a database connection.

What's the best way to share the project without giving out your password?

So far I've specifically removed it before committing any changes, but I'm thinking there has to be a better way.

4 Answers 4


One trick learned in the ASP classic days, was to have the connection string in an outside file.

''// Init the ADO objects  & the stored proc parameters
cmd.ActiveConnection = "file name=c:\udl\mydb.udl"
cmd.CommandText = sqlstmt
cmd.CommandType = adCmdStoredProc

It works in ADO, don't know your environment

  • I do this with PHP: put the connection string in a config file. Commented Oct 18, 2010 at 20:39
  • Thanks.. I did try this also, just thought there might be a better way. This is what I'll do, and document the requirement in the project.
    – Fosco
    Commented Oct 18, 2010 at 21:54
  • 2
    Further to this - it also means you don't tie the connection to the source code, which is - generally - a bad thing. You want to easily be able to specify your connection details on a per instance basis and therefore to design this kind of separation in from the start.
    – Murph
    Commented Oct 19, 2010 at 7:47

It sounds to me like you're sharing your code, but not the connection.

You may want to just store your password in a file outside your checkout or a file that is marked as ignored by your version control. I have a set of scripts at work that need my username/password that I shared, and I just have it look at ~/.live_db to get my info.


If you're using windows you can encrypt the connection string (e.g. like this) and share that but not the encryption key. I dare say that other platforms have similar capabilities.

Of course it'll be a waste of time unless that account is also locked down with limited privilages.


If you are sharing the uname and pwd, you should probably consider saving them in encrypted form.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.