使用 Windows 身份验证连接到数据库

Connecting to database using Windows Athentication

我想在我的程序中使用 window 身份验证来连接到我的 sql 服务器。用户已经在 SQL 服务器上拥有某些权限,我想在我的程序中利用它。我目前连接到服务器的方式是使用这个连接字符串。

Dim ConnectionString As String = "Data Source=Server;Initial Catalog = m2mdata02;User ID=ID;Password=Password;"

您需要添加 Integrated Security=SSPI 并从连接字符串中删除用户名和密码。

Dim ConnectionString As String = "Data Source=Server;Initial Catalog=m2mdata02;Integrated Security=SSPI;"