Question

I noticed that this question has been asked before and i have read the answers on both neither apply to my problem which I know the most likely solution to would be changing my code however i don't know how to do that and keep my application running the same way while debugging. I am using this connection string.

public string cnString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" + Path.GetFullPath(Application.StartupPath + "\\..\\..\\data.mdb");

my problem though is that the folder that the database file is in is not the same folder that the connection string connects to after deployment this then gives me the error that "data.mdb" is not located in xxxx. I know that the "\..\..\" is the reason for that however changing that would mean i can not debug the program without changing the connection string each time... What connection string is suppose to be used to ensure that both the application that is installed as well as the source code both run as they should, secondly what software that is free aside from install shield limited edition and the onclick that comes stand with visual studio 2013.

Was it helpful?

Solution

I'd use the debug preprocessor:

    #if DEBUG    
      'Your connection string
    #else
      'Live connection string
    #endif

Personally, I would simulate a live environment as much as possible to avoid situations like this. This means working as if the application is deployed. With the method described above, you wouldn't care if it's on your local machine or not, you just have to remember to build your app as "Release' instead of "Debug" when pushing it live.

Doing something just because it's easier to debug will make your life more difficult down the road.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top