为什么serverSelected为null? [英] Why serverSelected is null?

查看:96
本文介绍了为什么serverSelected为null?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ViewModel:



ViewModel :

string _serverSelected;
        public string serverSelected
        {
            get { return _serverSelected; }
            set
            {
                if (_serverSelected != value)
                    _serverSelected = value;

                RaisePropertyChanged("serverSelected");
            }
        }

        public BackUpViewModel()
        {

             BackUpContext servObj = new BackUpContext();
            _DBNameList = servObj.GetDBNames(serverSelected);
        }







DAL:






DAL :

public List<string> GetDBNames(string sqlServerName)
        {
    List<string> lstDBName = new List<string>();


                SqlConnectionStringBuilder connection = new SqlConnectionStringBuilder();
                connection.DataSource = sqlServerName;
                connection.IntegratedSecurity = true;
                String strCon = connection.ToString();
                SqlConnection sqlConn = new SqlConnection(strCon);
                sqlConn.Open();

                SqlCommand cmd = new SqlCommand("select * from sys.databases", sqlConn);
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    lstDBName.Add(dr[0].ToString());
                }
                sqlConn.Close();


                return lstDBName;
}







AppConfig:






AppConfig :

<configuration>
  <connectionStrings>

    <add name="CostAllocationEntities2" connectionString="Data Source=pc210090\SQLExpress;Persist Security Info=True;User ID=sa;Password=password1$" providerName="System.Data.SqlClient"/>
    </connectionStrings>

  <appSettings>

    <add key="ServerName1" value="PC210090\SQLEXPRESS"/>
    <add key="ServerName2" value="s2"/>
    <add key="ServerName3" value="s3"/>
    <add key="BackupDestinationPath" value="D:\BackUpDatabase\"/>
    <add key="RestoreDestinationPath" value="D:\RestoreDatabase\"/>

  </appSettings>
</configuration>










Quote:

_DBNameList = servObj.GetDBNames(serverSelected);这个serverSelected总是传递为null,这不允许我的代码构建,因此我无法从服务器列表中选择服务器。

_DBNameList = servObj.GetDBNames(serverSelected); this serverSelected is always passing as null which is not allowing my code to build and i am not able to select server from server list because of this.

推荐答案

providerName = System.Data.SqlClient / >
< / connectionStrings >

< appSettings >

< add key = 丝氨酸verName1 value = PC210090 \ SQLEXPRESS / >
< add key = ServerName2 value = s2 / >
< add key = ServerName3 = s3 / >
< add key = BackupDestinationPath = D:\ BackUpDatabase \ / >
< add key = RestoreDestinationPath value = D: \恢复数据库\ / >

< span class =code-keyword>< / appSettings >
< / configuration >
" providerName="System.Data.SqlClient"/> </connectionStrings> <appSettings> <add key="ServerName1" value="PC210090\SQLEXPRESS"/> <add key="ServerName2" value="s2"/> <add key="ServerName3" value="s3"/> <add key="BackupDestinationPath" value="D:\BackUpDatabase\"/> <add key="RestoreDestinationPath" value="D:\RestoreDatabase\"/> </appSettings> </configuration>










Quote:

_DBNameList = servObj.GetDBNames(serverSelected);这个serverSelected总是作为null传递,这不允许我的代码构建,因此我无法从服务器列表中选择服务器。

_DBNameList = servObj.GetDBNames(serverSelected); this serverSelected is always passing as null which is not allowing my code to build and i am not able to select server from server list because of this.


您好,在您的代码中,你没有提到数据库名称,只是这样提,



Hi, In your code, you did not mention the database name, just mention it like this,

connection.InitialCatalog = "YourDatabaseNameHere";


这篇关于为什么serverSelected为null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆