public bool ConnectTo(MasterEntry me, string username, string userpsw) { string filename = GetFileName(me); if (!File.Exists(filename)) { throw new Exception($"Nav faila: [{filename}]"); } if (CurrentDBTag != null) { try { Params.Save(); if (KlonsTableAdapterManager?.TUSERSTableAdapter?.Connection != null) { KlonsTableAdapterManager.TUSERSTableAdapter.Connection.StateChange -= Connection_StateChange; } } catch (Exception) { } } _klonsDataSetHelper = new DataSetHelper( typeof(KlonsADataSet), typeof(KlonsAdapters.TableAdapterManager), typeof(KlonsAdapters.QueriesTableAdapter), "ConnectionString1", KlonsA.Properties.Settings.Default); _dataSetHelpers["KlonsData"] = _klonsDataSetHelper; _klonsRepDataSetHelper = new DataSetHelper( typeof(KlonsARepDataSet), typeof(KlonsRepAdapters.TableAdapterManager), null, "ConnectionString1", KlonsA.Properties.Settings.Default); _dataSetHelpers["KlonsRep"] = _klonsRepDataSetHelper; string newconnstr = MasterList.GetTemplateByName(me.ConnStr); if (string.IsNullOrEmpty(newconnstr)) { newconnstr = "character set=UTF8;" + "data source=localhost;" + @"initial catalog={0};" + "user id=aivars;" + "password=parole"; } newconnstr = string.Format(newconnstr, filename, username); var s1 = CheckConnectionString(newconnstr); if (s1 == null) { throw new Exception($"Nekorekti pieslēguma dati:\n{newconnstr}"); } newconnstr = s1; _currentUserName = username; _klonsDataSetHelper.ConnectTo(newconnstr); _klonsRepDataSetHelper.ConnectTo(newconnstr); KlonsTableAdapterManager.TUSERSTableAdapter.Connection.StateChange += Connection_StateChange; KlonsTableAdapterManager.TUSERSTableAdapter.Connection.Open(); CurrentDBTag = new MasterEntry(me); return(true); }