简体   繁体   English

Visual Studio 文件夹文件路径

[英]Visual Studio Folder file path

I have folder in my project called "Database".我的项目中有一个名为“数据库”的文件夹。 Inside that folder is the file "topicalconcordance.sqlite".该文件夹内是文件“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?如何在此处修改我的路径,使其指向我文件夹中的 internal.sqlite 文件?

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.您可以将连接存储在 app.config 文件中,也可以将其存储在设置文件中。 Then you can just change the path of the connection, without having to rebuild you application.然后你可以改变连接的路径,而不必重建你的应用程序。

You app.config file will look like this.您的 app.config 文件将如下所示。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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