开发者

Visual Studio Folder file path

开发者 https://www.devze.com 2023-03-17 00:39 出处:网络
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:

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();
0

精彩评论

暂无评论...
验证码 换一张
取 消