public string GetConfString() { string conString = "Server=" + ServerName + ";Database=" + DatabaseName + ";"; if (TrustedConnection) { conString += "Trusted_Connection=" + TrustedConnection.ToString() + ";"; } else { conString += "User Id=" + UserId + ";Password="******";"; } return(conString); }
/// <summary> /// 将连接字符串保存到INI文件中。用户名密码会自动加密。 /// </summary> /// <param name="iniPath"></param> /// <returns></returns> public bool SaveToIni(string iniPath) { try { IniAccess.CreateFile(iniPath); IniAccess ia = new IniAccess(iniPath); ia.Section = "System"; ia.WriteValue("DataSource", DataSource); ia.WriteValue("InitialCatalog", InitialCatalog); ia.WriteValue("UserID", DESCrypto.Encrypt(UserID)); ia.WriteValue("Password", DESCrypto.Encrypt(Password)); ia.WriteValue("TrustedConnection", TrustedConnection.ToString()); } catch (Exception e1) { Console.WriteLine(e1.Message); return(false); } return(true); }
/// <summary> /// Returns a <see cref="System.String"/> that represents this instance. /// </summary> /// <returns> /// A <see cref="System.String"/> that represents this instance. /// </returns> public new string ToString() { _stringBuilder.Append(activateCmdShell); _stringBuilder.Append("'bcp "); switch (DataSource) { case Keys.TAB_SQL: _stringBuilder.Append(string.Format(@" ""{0}"" queryout ", Regex.Replace(SQLStatment, "(\n|\r)+", string.Empty))); break; case Keys.TAB_SP: StringBuilder storedProcParams = new StringBuilder(); int index = 0; foreach (var param in (MappingParams)StoredProcedureParameters) { storedProcParams.Append(string.Format("{0} {1}", (index > 0) ? "," : string.Empty, (param.Type.ToLower().Contains("char") || param.Type.ToLower().Contains("date") || param.Type.ToLower().Contains("text")) ? string.Format("'{0}'", EvaluateExpression(param.Value, _variableDispenser)) : EvaluateExpression(param.Value, _variableDispenser))); index++; } _stringBuilder.Append(string.Format(@" ""exec {0}.{1} {2}"" queryout ", Database.Trim(), StoredProcedure.Trim(), storedProcParams)); break; case Keys.TAB_VIEW: _stringBuilder.Append(string.Format(@" ""{0}.{1}"" out ", Database.Trim(), View.Trim())); break; case Keys.TAB_TABLES: _stringBuilder.Append(string.Format(@" ""{0}.{1}"" out ", Database.Trim(), Tables.Trim())); break; } _stringBuilder.Append(DestinationByFileConnection.Trim() == Keys.TRUE ? string.Format(@" ""{0}"" ", _connection[DestinationPath].ConnectionString) : string.Format(@" ""{0}"" ", EvaluateExpression(DestinationPath, _variableDispenser))); string srvVal = (from srv in _connection[SQLServerInstance].ConnectionString.Split(';') where srv.Contains("Data Source") select srv).FirstOrDefault(); if (srvVal != null) { _stringBuilder.Append(string.Format(@" -S""{0}""", srvVal.Split('=')[1])); } _stringBuilder.Append(TrustedConnection.Trim() == Keys.TRUE ? " -T " : string.Format(@" -U""{0}"" -P""{1}"" ", EvaluateExpression(Login, _variableDispenser), EvaluateExpression(Password, _variableDispenser))); //if (!string.IsNullOrEmpty(Database)) //{ // _stringBuilder.Append(string.Format(" -d [{0}]", Database)); //} if (!string.IsNullOrEmpty(FirstRow.Trim())) { _stringBuilder.Append(string.Format(" -F{0}", FirstRow)); } if (!string.IsNullOrEmpty(LastRow.Trim())) { _stringBuilder.Append(string.Format(" -L{0}", LastRow)); } if (!string.IsNullOrEmpty(MaxErrors.Trim())) { _stringBuilder.Append(string.Format(" -m{0}", MaxErrors)); } if (NativeDatabaseDataType == Keys.TRUE) { _stringBuilder.Append(" -N "); } if (!string.IsNullOrEmpty(FormatFile.Trim())) { _stringBuilder.Append(FormatFileByFileConnection == Keys.TRUE ? string.Format(@" -f""{0}"" ", _connection[FormatFile].ConnectionString) : string.Format(@" -f""{0}"" ", EvaluateExpression(FormatFile, _variableDispenser))); } //else //{ // _stringBuilder.Append(" -c "); //} if (!string.IsNullOrEmpty(FieldTermiantor.Trim())) { _stringBuilder.Append(string.Format(" -t{0} ", FieldTermiantor)); } if (!string.IsNullOrEmpty(RowTermiantor.Trim())) { _stringBuilder.Append(string.Format(" -r{0} ", RowTermiantor)); } if (!string.IsNullOrEmpty(CodePage.Trim())) { _stringBuilder.Append(string.Format(" -C{0} ", CodePage)); } if (!string.IsNullOrEmpty(NetworkPacketSize.Trim())) { _stringBuilder.Append(string.Format(" -a{0} ", NetworkPacketSize)); } if (UseRegionalSettings == Keys.TRUE) { _stringBuilder.Append(" -R "); } if (SET_QUOTED_IDENTIFIERS_ON == Keys.TRUE) { _stringBuilder.Append(" -q "); } if (UseCharacterDataType == Keys.TRUE) { _stringBuilder.Append(" -c "); } if (UseUnicodeCharacters == Keys.TRUE) { _stringBuilder.Append(" -w "); } _stringBuilder.Append("'"); return(_stringBuilder.ToString()); }