简体   繁体   中英

Value cannot be null. Parameter name: path

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");

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM