示例#1
0
 public static void SetConnectionString(string p_ConnectionString, string server, string database, string user, string password, string applicationName)
 {
     System.Data.SqlClient.SqlConnectionStringBuilder builder = new System.Data.SqlClient.SqlConnectionStringBuilder(p_ConnectionString);
     if (!string.IsNullOrEmpty(server))
     {
         builder.set_DataSource(server);
     }
     if (!string.IsNullOrEmpty(database))
     {
         builder.set_InitialCatalog(database);
     }
     if (!string.IsNullOrEmpty(user))
     {
         builder.set_UserID(user);
         builder.set_Password(password);
     }
     else
     {
         builder.set_IntegratedSecurity(true);
     }
     builder.set_ConnectTimeout(10);
     if (string.IsNullOrEmpty(applicationName))
     {
         builder.set_ApplicationName(string.Format("{0} [{1}]", EntryAssembly.GetTitle(), EntryAssembly.Version));
     }
     else
     {
         builder.set_ApplicationName(applicationName);
     }
     ConnectionString = builder.get_ConnectionString();
 }