com.rusanu.DBUtil.SqlCmd.ConnectCommand C# (CSharp) Метод

ConnectCommand() приватный Метод

private ConnectCommand ( string line ) : void
line string
Результат void
		private void ConnectCommand (string line) {
			// server_name[\instance_name] [-l timeout] [-U user_name [-P password]] 
			var regConnect = new Regex (@"^:connect\s+(?<server>[^\s]+)(?:\s+-l\s+(?<timeout>[\d]+))?(?:\s+-U\s+(?<user>[^\s]+))?(?:\s+-P\s+(?<password>[^\s]+))?", RegexOptions.IgnoreCase);
			MatchCollection connectMatches = regConnect.Matches (line);

			if (connectMatches.Count != 1) {
				throw new SqlCmdConnectSyntaxException (line);
			}

			Match m = connectMatches [0];

			var scsb = new SqlConnectionStringBuilder ();

			Group serverGroup = m.Groups ["server"];
			if (false == serverGroup.Success) {
				throw new SqlCmdConnectSyntaxException (line);
			}
			scsb.DataSource = m.Groups ["server"].Value;

			Group timeoutGroup = m.Groups ["timeout"];
			if (timeoutGroup.Success) {
				int timeout = Convert.ToInt32 (timeoutGroup.Value);
				scsb.ConnectTimeout = timeout;
			}

			Group userGroup = m.Groups ["user"];
			if (userGroup.Success) {
				scsb.UserID = userGroup.Value;
				Group passwordGroup = m.Groups ["password"];
				if (passwordGroup.Success) {
					scsb.Password = passwordGroup.Value;
				}
			} else {
				scsb.IntegratedSecurity = true;
			}

			if (null != _privateConnection) {
				_privateConnection.Dispose ();
			}
			_privateConnection = new SqlConnection (scsb.ConnectionString);
			_privateConnection.Open ();
			Environment.Connection = _privateConnection;
		}