# Koppelung der SQL Express Datenbank in MDT

Die Verbindung zwischen MDT und der SQL-Express-Datenbank wird nun konfiguriert. Durch die Datenbank wird die Erfassung unterschiedlicher Bereitstellungs-Optionen erheblich vereinfacht.&#x20;

Die Konfiguration der Verknüpfung zwischen SQL-Datenbank und MDT ist komplex. Empfohlen wird daher diese Konfiguration mit Hilfe des Videos durchzuführen:

{% embed url="<https://youtu.be/uGvkvUBWI5A>" %}
Koppelung der SQL-Express-Datenbank in MDT
{% endembed %}

{% hint style="danger" %}
**Achtung!** Der Name der Datenbank muss übereinstimmen mit dem im SQL Server Configuration Manager. Der Standardname ist `SQLEXPRESS`, im Video ist er `ADK`.

Du hast dir diesen Namen bei der Installation von SSMS notiert (siehe [Installation des SQL Server Express](https://do-moser.gitbook.io/server-virtualization/mdt-dienste-installieren#installation-des-sql-server-express-frueher-in-adk-integriert)).
{% endhint %}

Optional wird hier über die Ausführung des Skripts `SetSQLServicesMDT.ps1` die Einrichtung vereinfacht:

{% code title="ConfigSQLExpressMDT.ps1" %}

```powershell
Add-PSSnapIn Microsoft.BDD.PSSnapIn -ErrorAction SilentlyContinue 
Get-PSDrive -PSProvider Microsoft.BDD.PSSnapIn\MDTProvider  | Remove-PSDrive | Remove-MDTPersistentDrive
New-PSDrive -Name "DS001" -PSProvider MDTProvider `
  -Root "$InstallDrive\MDTProdLab" `
  -Description "MDT ProdLab" `
  -NetworkPath "\\$MDT01\MDTProdLab$"

# How to: Enable or Disable a Server Network Protocol (SQL Server PowerShell)
# https://technet.microsoft.com/en-us/library/dd206997(v=sql.105).aspx
[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")
[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.SqlWmiManagement")
$smo = 'Microsoft.SqlServer.Management.Smo.'
$wmi = new-object ($smo + 'Wmi.ManagedComputer').
# List the object properties, including the instance names.
$Wmi
# Disable the TCP protocol on the default instance.
# $uri = "ManagedComputer[@Name='$MDTServer']/ ServerInstance[@Name='ADK']/ServerProtocol[@Name='Tcp']"
$uri = "ManagedComputer[@Name='" + (get-item env:\computername).Value + "']/ServerInstance[@Name='ADK']/ServerProtocol[@Name='Tcp']"
$Tcp = $wmi.GetSmoObject($uri)
$Tcp.IsEnabled = $false
$Tcp.Alter()
$Tcp
# Enable the named pipes protocol for the default instance.
$uri = "ManagedComputer[@Name='" + (get-item env:\computername).Value + "']/ServerInstance[@Name='ADK']/ServerProtocol[@Name='Np']"
# $uri = "ManagedComputer[@Name='$MDTServer']/ ServerInstance[@Name='ADK']/ServerProtocol[@Name='Np']"
$Np = $wmi.GetSmoObject($uri)
$Np.IsEnabled = $true
$Np.Alter()
$Np

Start-Sleep -Milliseconds 1000

Start-Process sc -ArgumentList {config sqlbrowser start= auto} -ErrorAction SilentlyContinue
Start-Service "SQL Server Browser" -ErrorAction SilentlyContinue
Stop-Service "SQL Server (ADK)"  -ErrorAction SilentlyContinue
Start-Service "SQL Server (ADK)" -ErrorAction SilentlyContinue

Start-Sleep -Milliseconds 1000

# Add a new Database
$MDTServer = (get-wmiobject win32_computersystem).Name
New-MDTDatabase -SQLServer $MDTServer -Database "DB-Prod-Lab" -Instance "ADK" -SQLShare "MDTProdLab$" -Path DS001: -Force 
```

{% endcode %}
