配置管理器 returns Null 而不是连接字符串
Configuration Manager returns Null instead of Connection string
我想从 App.config 中检索字符串连接,正如我在教程中看到的那样
但我在 visual studio 中看不到 app.config。
我点击了图片中的项目名称
打开此选项卡并输入以下代码
这是获取连接字符串的C#代码
public static string GetConnectionString(string name)
{
string returnValue = null;
ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings[name];
if (settings != null)
returnValue = settings.ConnectionString;
return returnValue;
}
仍然,我只得到 null 而不是我想要的连接字符串,我很困惑
我在 winforms 和控制台上尝试了相同的代码,但效果不佳
如有任何帮助,我们将不胜感激
app.config 您的项目中缺少文件
右键单击项目配置文件并将其命名为 app.config 添加后它将显示在您的项目中,如下所示
enter image description here
并将以下代码添加到 app.config 并将连接字符串替换为您的
连接字符串值
enter image description here
我想从 App.config 中检索字符串连接,正如我在教程中看到的那样
但我在 visual studio 中看不到 app.config。
我点击了图片中的项目名称
打开此选项卡并输入以下代码
这是获取连接字符串的C#代码
public static string GetConnectionString(string name)
{
string returnValue = null;
ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings[name];
if (settings != null)
returnValue = settings.ConnectionString;
return returnValue;
}
仍然,我只得到 null 而不是我想要的连接字符串,我很困惑
我在 winforms 和控制台上尝试了相同的代码,但效果不佳
如有任何帮助,我们将不胜感激
app.config 您的项目中缺少文件 右键单击项目配置文件并将其命名为 app.config 添加后它将显示在您的项目中,如下所示 enter image description here
并将以下代码添加到 app.config 并将连接字符串替换为您的 连接字符串值 enter image description here