我正在研究三层架构。我需要通过业务层从 UI 中传递数据访问层中的服务器名称。为了传递值,我正在使用属性,并且我成功地在我的数据层中获取了值。但是当我尝试连接字符串来为我的数据库连接生成数据源时,它会传递空值。
我的代码:
public class dataLayer: IDisposable
{
private string serverName;
private string name;
private string ceConnString;
public string ServerName
{
get { return serverName; }
set { serverName = value; }
}
public dataLayer()
{
//First Try - Using Simple Concatination
name = @"\\" + ServerName + @"\foldername\Database.sdf;";
//result - name = \\\\\\foldername\Database.sdf
//Second Try - Using String Builder
StringBuilder build = new StringBuilder();
build.Append("\\\\");
build.Append(ServerName);
build.Append("\\foldername\\Database.sdf;");
string namebuilder = build.ToString();
//result - namebuilder = \\\\\\foldername\Database.sdf
//Third Try - Using Path
string line = Path.Combine("\\\\", ServerName, \\foldername\\Database.sdf;");
//result - line = \\\\\\foldername\Database.sdf
ceConnString = "data source=" + name;
}
我希望输出为\\server name\foldername\Database.sdf