vb.net 使用 Windows 身份验证模式的连接字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12974004/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Connection String with Windows Authentication Mode
提问by disasterkid
I'm trying to test a simple connection to my database with VB.NET on my SQL Server 2008. The problem is my login is with Windows Authentication mode and I enter no password for it to connect to my SQL server.
我正在尝试在我的 SQL Server 2008 上使用 VB.NET 测试到我的数据库的简单连接。问题是我的登录是使用 Windows 身份验证模式,我没有输入密码来连接到我的 SQL 服务器。
How will a connection string in this case look like? This has blocked my progress for the whole day.
在这种情况下,连接字符串会是什么样子?这阻碍了我一整天的进步。
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connetionString As String
Dim connection As SqlConnection
Dim i As Integer
connetionString = "Data Source=PEDRAM-PC\PEDRAM;Initial Catalog=Test;User ID=Pedram-PC\Pedram;Password=bro"
connection = New SqlConnection(connetionString)
Try
connection.Open()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class
回答by SLaks
Add Integrated Security=SSPI
instead of the username and password.
添加Integrated Security=SSPI
而不是用户名和密码。