我想知道如何从asp.net中的web.config文件获取连接字符串。从asp.net中的Web.config获取连接字符串
我只知道下面的方法。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
namespace Sherserve.DataAccessLayer
{
public class DBGateway
{
public static string conString;
public DBGateway()
{
conString = ConfigurationManager.ConnectionStrings["test"].ToString();
}
}
}
它应该是'ConfigurationManager.ConnectionStrings [ “test”] .ConnectionString;'但这是你唯一正确的方式。 –
因此最新错误 conString = ConfigurationManager.ConnectionStrings [“test”]。ToString(); –
@Mitch请参阅[this](http://meta.stackexchange.com/questions/76195/how-to-deal-with-have-you-tried-google-comments) - 您的评论对任何人都不是很有建设性。 –