简体   繁体   中英

Visual Studio Folder file path

I have folder in my project called "Database". Inside that folder is the file "topicalconcordance.sqlite". I am trying to locate the db and connect to it like so:

using (DbConnection cnn = new SQLiteConnection("Data Source=myDbPath/topicalconcordance.sqlite"))

How do I modify my path here so it points to the internal.sqlite file in my folder?

Is there a better way to access and modify and store an internal file like I have?

You can store you connection in your app.config file, or you can store it in a setting file. Then you can just change the path of the connection, without having to rebuild you application.

You app.config file will look like this.

<?xml version="1.0"?>
<configuration>
  <connectionStrings>
    <add name="Conn" connectionString="Data Source=myDbPath/topicalconcordance.sqlite" />
  </connectionStrings>
</configuration>

You can call get the connection in code behind.

string connection = ConfigurationManager.ConnectionStrings["Conn"].ConnectionString();

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