1

I am trying to build my first .exe from a c# winforms project. I am using the Flexera Installing Shield. So far I can build and install it and it runs successfully on the same machine where I am developing. In this project I am using a local db. I can also install it on another machine, but as soon as I`m trying to access the Db via a button it complains. I think it has something to do with the connection string. At least it complains at the line where I am trying to access the Db with:

Error 26 - Error Locating Server/Instance Specified 

Here is my obviously wrong connection string:

string connectionString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=""C:\Users\idiot\Documents\Visual Studio 2013\Projects\Vis\Vis\LocalDbVisTest.mdf"";Integrated Security=True";

Thank you for any help or hint in advance!

3
  • did you copy the database along with your program? It will need to reside in this path: C:\Users\idiot\Documents\Visual Studio 2013\Projects\Vis\Vis\LocalDbVisTest.mdf Commented Feb 3, 2014 at 20:45
  • Do you have the same problem if you build and run the created installer manually? If so, if could be a configuration issue with Flexara. Commented Feb 3, 2014 at 20:45
  • No, I built the .exe on my machine where I develop, and installed it on another machine, where it does not work. I have no idea how to build manually. Sorry, first time I try to do this. Commented Feb 3, 2014 at 20:50

1 Answer 1

5

Instead of using an absolute path for your connection string, use

Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\LocalDbVisTest.mdf;Integrated Security=True

The reason your program cannot find the database is because it is looking in

C:\Users\idiot\Documents\Visual Studio 2013\Projects\Vis\Vis\LocalDbVisTest.mdf

Which, presumably, doesn't exist on your client's machine.

You can manually set your DataDirectory by using AppDomain.CurrentDomain.SetData("DataDirectory", path). You can get the path of your executable by using AppDomain.CurrentDomain.BaseDirectory

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

5 Comments

Thx, I just built it new. It works so to say better. But it complains that the database is read-only?
Hmm not sure about that one I'm afraid! Sorry.
@dav_i You are going to have to change the permissions for the Db.
@Dozer: any idea where I can change the permissions for the local Db?
I don't really know very much about web hosting, but the only way I could answer that, would be if knew what hosting provider you were using.

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.