示例#1
1
 private static SqlConnection CreateConnection(Args args)
 {
     var database = args.GetValue("database");
     var server = args.GetValueOrDefault("server", Environment.MachineName);
     var user = args.GetValueOrNull("user");
     var password = args.GetValueOrNull("password");
     var credentials = user == null
                                 ? "Integrated Security=True"
                                 : string.Format("User ID={0};Password={1}", user, password);
     var connectionString = string.Format("Server={0};Database={1};{2}", server, database, credentials);
     var connection = new SqlConnection(connectionString);
     connection.Open();
     return connection;
 }