31 lines
		
	
	
		
			991 B
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			31 lines
		
	
	
		
			991 B
		
	
	
	
		
			C#
		
	
	
	
	
	
| namespace DBMigration.Models
 | |
| {
 | |
|     public class ConnectionInfo
 | |
|     {
 | |
|         public string ServerName { get; set; } = string.Empty;
 | |
|         public string DatabaseName { get; set; } = string.Empty;
 | |
|         public string UserId { get; set; } = string.Empty;
 | |
|         public string Password { get; set; } = string.Empty;
 | |
|         public bool UseWindowsAuthentication { get; set; }
 | |
| 
 | |
|         public string GetConnectionString()
 | |
|         {
 | |
|             var builder = new Microsoft.Data.SqlClient.SqlConnectionStringBuilder
 | |
|             {
 | |
|                 DataSource = ServerName,
 | |
|                 InitialCatalog = DatabaseName,
 | |
|                 IntegratedSecurity = UseWindowsAuthentication,
 | |
|                 TrustServerCertificate = true
 | |
|             };
 | |
| 
 | |
|             if (!UseWindowsAuthentication)
 | |
|             {
 | |
|                 builder.UserID = UserId;
 | |
|                 builder.Password = Password;
 | |
|             }
 | |
| 
 | |
|             return builder.ConnectionString;
 | |
|         }
 | |
|     }
 | |
| }
 | 
