Esempio n. 1
0
        public static ExecutionContext Create(Data.ConnectionDetails connectionDetails)
        {
            Data.DatabaseConnector.TestResult oResult = Data.DatabaseConnector.Test(connectionDetails);

            if (!oResult.Success)
            {
                throw new ApplicationException(oResult.Message);
            }

            return(new ExecutionContext(new Data.DatabaseConnector(connectionDetails)));
        }
Esempio n. 2
0
		private static string BuildConnectionString(ConnectionDetails connectionDetails)
		{
			string sConnectString;

			if (connectionDetails.ConnectionType == DatabaseConnectionType.WindowsIntegrated)
				sConnectString = string.Format("Server={0};Database={1};Integrated Security=SSPI;", connectionDetails.ServerName, connectionDetails.DBName);
			else
				sConnectString = string.Format("Server={0};Database={1};User={2};Password={3}", connectionDetails.ServerName, connectionDetails.DBName, connectionDetails.SQLUsername, connectionDetails.SQLPassword);

			return (sConnectString);
		}
Esempio n. 3
0
		public static TestResult Test(ConnectionDetails connectionDetails)
		{
			try
			{
				using (SqlConnection oConnection = new SqlConnection(DatabaseConnector.BuildConnectionString(connectionDetails)))
				{
					oConnection.Open();
				}

				return (new TestResult(true, string.Empty));
			}
			catch (Exception ex)
			{
				return (new TestResult(false, ex.Message));
			}
		}
Esempio n. 4
0
		public DatabaseConnector(ConnectionDetails connectionDetails)
		{
			_ConnectionDetails = connectionDetails;
			_Connection = new SqlConnection(this.BuildConnectionString());
			_Connection.Open();
		}
Esempio n. 5
0
        private static ExecutionContext GetContextFromCommandLine(string [] args)
        {
            if (args == null || args.Length == 0)
            {
                return(null);
            }

            ExecutionContext oContext = null;
            string           sServer  = null;
            string           sDB      = null;

            Data.DatabaseConnectionType nConnectionType = Data.DatabaseConnectionType.WindowsIntegrated;
            string sPwd  = null;
            string sUser = null;

            foreach (string sArg in args)
            {
                if (System.Text.RegularExpressions.Regex.IsMatch(sArg, @"^[-/]([Hh?]|help|Help|HELP)$"))
                {
                    MessageBox.Show("Sharepoint2003.DBExporter.exe -s:<server> -d:<database> -a:W|S [-u:<username> -p:<password>]\n\n" +
                                    "s:<server>	= server name\n" +
                                    "d:<database>	= database name\n"+
                                    "a:W|S		= authentication mode ([W]indows integrated or [S]QL server)\n"+
                                    "u:<username>	= username for sql server authentication\n"+
                                    "p:<password>	= password for sql server authentication");

                    return(ExecutionContext.None);
                }

                System.Text.RegularExpressions.Match oMatch = null;

                oMatch = System.Text.RegularExpressions.Regex.Match(sArg, @"^[-/]s:(?<val>[^ ]+)$");
                if (oMatch.Success)
                {
                    sServer = oMatch.Groups["val"].Value;
                }

                oMatch = System.Text.RegularExpressions.Regex.Match(sArg, @"^[-/]d:(?<val>[^ ]+)$");
                if (oMatch.Success)
                {
                    sDB = oMatch.Groups["val"].Value;
                }

                oMatch = System.Text.RegularExpressions.Regex.Match(sArg, @"^[-/]a:(?<val>[WwSs])$");
                if (oMatch.Success)
                {
                    nConnectionType = (oMatch.Groups["val"].Value.ToLower() == "w") ? Data.DatabaseConnectionType.WindowsIntegrated : Data.DatabaseConnectionType.SQLAuthentication;
                }

                oMatch = System.Text.RegularExpressions.Regex.Match(sArg, @"^[-/]p:(?<val>[^ ]+)$");
                if (oMatch.Success)
                {
                    sPwd = oMatch.Groups["val"].Value;
                }

                oMatch = System.Text.RegularExpressions.Regex.Match(sArg, @"^[-/]u:(?<val>[^ ]+)$");
                if (oMatch.Success)
                {
                    sUser = oMatch.Groups["val"].Value;
                }
            }

            if (sServer != null && sServer.Length > 0)
            {
                Data.ConnectionDetails            oDetails = new Data.ConnectionDetails(sServer, sDB, nConnectionType, sUser, sPwd, 0);
                Data.DatabaseConnector.TestResult oResult  = Data.DatabaseConnector.Test(oDetails);

                if (oResult.Success)
                {
                    oContext = ExecutionContext.Create(oDetails);
                }
                else
                {
                    MessageBox.Show(oResult.Message);
                }
            }

            return(oContext);
        }
Esempio n. 6
0
		private static ExecutionContext GetContextFromCommandLine(string [] args)
		{
			if (args == null || args.Length == 0)
				return (null);

			ExecutionContext oContext = null;
			string sServer = null;
			string sDB = null;
			Data.DatabaseConnectionType nConnectionType = Data.DatabaseConnectionType.WindowsIntegrated;
			string sPwd = null;
			string sUser = null;

			foreach (string sArg in args)
			{
				if (System.Text.RegularExpressions.Regex.IsMatch(sArg, @"^[-/]([Hh?]|help|Help|HELP)$"))
				{
					MessageBox.Show("Sharepoint2003.DBExporter.exe -s:<server> -d:<database> -a:W|S [-u:<username> -p:<password>]\n\n" +
						"s:<server>	= server name\n" + 
						"d:<database>	= database name\n" +
						"a:W|S		= authentication mode ([W]indows integrated or [S]QL server)\n" +
						"u:<username>	= username for sql server authentication\n" +
						"p:<password>	= password for sql server authentication");

					return (ExecutionContext.None);
				}

				System.Text.RegularExpressions.Match oMatch = null;
				
				oMatch = System.Text.RegularExpressions.Regex.Match(sArg, @"^[-/]s:(?<val>[^ ]+)$");
				if (oMatch.Success)
					sServer = oMatch.Groups["val"].Value;

				oMatch = System.Text.RegularExpressions.Regex.Match(sArg, @"^[-/]d:(?<val>[^ ]+)$");
				if (oMatch.Success)
					sDB = oMatch.Groups["val"].Value;

				oMatch = System.Text.RegularExpressions.Regex.Match(sArg, @"^[-/]a:(?<val>[WwSs])$");
				if (oMatch.Success)
					nConnectionType = (oMatch.Groups["val"].Value.ToLower() == "w") ? Data.DatabaseConnectionType.WindowsIntegrated : Data.DatabaseConnectionType.SQLAuthentication;

				oMatch = System.Text.RegularExpressions.Regex.Match(sArg, @"^[-/]p:(?<val>[^ ]+)$");
				if (oMatch.Success)
					sPwd = oMatch.Groups["val"].Value;

				oMatch = System.Text.RegularExpressions.Regex.Match(sArg, @"^[-/]u:(?<val>[^ ]+)$");
				if (oMatch.Success)
					sUser = oMatch.Groups["val"].Value;
			}

			if (sServer != null && sServer.Length > 0)
			{
				Data.ConnectionDetails oDetails = new Data.ConnectionDetails(sServer, sDB, nConnectionType, sUser, sPwd, 0);
				Data.DatabaseConnector.TestResult oResult = Data.DatabaseConnector.Test(oDetails);

				if (oResult.Success)
					oContext = ExecutionContext.Create(oDetails);
				else
					MessageBox.Show(oResult.Message);
			}
				
			return (oContext);
		}
Esempio n. 7
0
 public DatabaseConnector(ConnectionDetails connectionDetails)
 {
     _ConnectionDetails = connectionDetails;
     _Connection        = new SqlConnection(this.BuildConnectionString());
     _Connection.Open();
 }