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))); }
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); }
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)); } }
public DatabaseConnector(ConnectionDetails connectionDetails) { _ConnectionDetails = connectionDetails; _Connection = new SqlConnection(this.BuildConnectionString()); _Connection.Open(); }
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); }
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); }
public DatabaseConnector(ConnectionDetails connectionDetails) { _ConnectionDetails = connectionDetails; _Connection = new SqlConnection(this.BuildConnectionString()); _Connection.Open(); }