//gets data source public string getSource(DBserver server) { Console.Write("Server Name: "); server.serverName = Console.ReadLine().Trim(); Console.Write("Database Name: "); server.dbName = Console.ReadLine().Trim(); string source = ""; Console.Write("Use Windows Authentication [Y/N]? "); string auth = Console.ReadLine().Trim(); if (auth.ToLower() == "y") { server.winAuth = true; source = String.Format("Data source={0}; Initial Catalog={1}; Integrated Security=True; Connection Timeout=15;", server.serverName, server.dbName); } else if (auth.ToLower() == "n") { server.winAuth = false; Console.WriteLine("\r\nUsing SQL Authentication:"); Console.Write("{0,12}", "Username: "******"Data source={0}; Initial Catalog={1}; User id= {2}; password={3}; Connection Timeout=15;", server.serverName, server.dbName, server.uName, server.pwd); } else { throw new Exception(); } return(source); }
//initializes SQL connection //throws exception if it cannot connect public void initializeSQL() { DBserver server = new DBserver(); Console.WriteLine("\r\n" + String.Concat(Enumerable.Repeat("*", 32))); Console.WriteLine("Initializing SQL Server"); Console.WriteLine(String.Concat(Enumerable.Repeat("*", 32))); con.ConnectionString = getSource(server); Console.WriteLine(String.Concat(Enumerable.Repeat("*", 32))); Console.WriteLine("Testing Connection..."); if (testConnection(con.ConnectionString) == true) { Console.WriteLine("Connected."); } else { throw new Exception(); } }
//initializes SQL connection //throws exception if it cannot connect public void initializeSQL() { DBserver server = new DBserver(); Console.WriteLine("\r\n" + String.Concat(Enumerable.Repeat("*", 32))); Console.WriteLine("Initializing SQL Server"); Console.WriteLine(String.Concat(Enumerable.Repeat("*", 32))); con.ConnectionString = getSource(server); Console.WriteLine(String.Concat(Enumerable.Repeat("*", 32))); Console.WriteLine("Testing Connection..."); if (testConnection(con.ConnectionString) == true) Console.WriteLine("Connected."); else throw new Exception(); }
//gets data source public string getSource(DBserver server) { Console.Write("Server Name: "); server.serverName = Console.ReadLine().Trim(); Console.Write("Database Name: "); server.dbName = Console.ReadLine().Trim(); string source = ""; Console.Write("Use Windows Authentication [Y/N]? "); string auth = Console.ReadLine().Trim(); if (auth.ToLower() == "y") { server.winAuth = true; source = String.Format("Data source={0}; Initial Catalog={1}; Integrated Security=True; Connection Timeout=15;", server.serverName, server.dbName); } else if (auth.ToLower() == "n") { server.winAuth = false; Console.WriteLine("\r\nUsing SQL Authentication:"); Console.Write("{0,12}", "Username: "******"Data source={0}; Initial Catalog={1}; User id= {2}; password={3}; Connection Timeout=15;", server.serverName, server.dbName, server.uName, server.pwd); } else { throw new Exception(); } return source; }