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); }
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; }
<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); 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.
connection.InitialCatalog = "YourDatabaseNameHere";
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)