2

I'm working with a local dataBase in a Windows Form Application and I'm trying to implement the source for the dataBase as DataDirectory, so in case I'm moving the db from one computer to another, it will work just fine. I wrote the following code, but I get this error, that the value cannot be null, at the line where it gets the Fullpath. Thanks !

var dataDirectory = ConfigurationManager.AppSettings["DataDirectory"];
var absoluteDataDirectory = Path.GetFullPath(dataDirectory);
AppDomain.CurrentDomain.SetData("DataDirectory", absoluteDataDirectory);
var connString = (@"Data Source= |DataDirectory|\Angajati.sdf");
Alexander Schmidt
  • 5,631
  • 4
  • 39
  • 79
Ezekiel
  • 333
  • 4
  • 9
  • 27

1 Answers1

1

You should have this section in your app.config:

<appSettings>
    <add key="DataDirectory" value="DataDirectoryPath"/>
</appSettings>

By the way for accessing DataDirectory you have to use this code:

AppDomain.CurrentDomain.GetData("DataDirectory")

more info.

Community
  • 1
  • 1
Sirwan Afifi
  • 10,654
  • 14
  • 63
  • 110
  • Works. Shows that the path is correct, but it doesn't insert in the db. I mean. It goes till the /Debug but then enter a folder named DataDirectoryPath. why? – Ezekiel Aug 27 '15 at 07:00