English 中文(简体)
App.Config Line String
原标题:App.Config Connection String

在我的窗户中,我有线搭桥。

<configuration>
    <configSections>
    </configSections>
    <connectionStrings>
        <add name="Database"
            connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|Database.accdb"
            providerName="System.Data.OleDb" />
    </connectionStrings>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
</configuration>

在所有类别中,我都使用以下代码连接数据库。

string connString = ConfigurationManager.ConnectionStrings["Database"].ConnectionString;

但它与数据库没有联系。

有些人可以指出错误。

But when i use this code without use of app.config it works fine.

   string connString  = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source = C:\Users\Amrit\Desktop\Database.accdb; Persist Security Info = False;";

如何打断连接线,从而扼杀工作。

问题回答

您可以这样做。

<configuration>
 <appSettings>
   <add key="ApplicationTitle" value="Sample Console Application" />
   <add key="ConnectionString"
       value="Server=localhost;Database=Northwind;Integrated
              Security=false;User Id=sa;Password=;" />
</appSettings>

然后使用<代码>ConfigurationSettings.AppSettings[“ConnectionString”];。

It seams (from the comments) that you are targeting two difference database files in those two connection strings. The first one is in your App_Data folder of your project, and the second one resides on your desktop.

页: 1 它超越了以前档案内容,因此每当你有一份新文件,即:<代码>App_Data>/code>在你产出夹中的倍数。 找到、实施方案并实施一些插入。 然后关闭方案,并在产出夹中打开数据库档案(不是在项目<代码>App_Data<>/code)。

这是因为你制定了<代码>。 http://www.un.org/Depts/DGACM/index_french.htm 总是。

你们需要建立数据目录。

那么,你就可以在申请中找到一条道路。 一开始 Global.ascx.cs

AppDomain.CurrentDomain.SetData("DataDirectory", "C:UsersAmritDesktop");

https://stackoverflow.com/a/1409378/2745294

希望这一帮助。





相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.

热门标签