Sql server 在VB.NET中连接到非本地SQL Server数据库
我正在尝试连接到非本地的SQL Server数据库。我有数据源和初始目录-没有问题。但需要将集成安全性更改为False并插入SQL Server凭据 有人知道如何将其放入连接字符串中吗 还有,有人知道如何处理SecureStrings吗 以下是我目前的代码:Sql server 在VB.NET中连接到非本地SQL Server数据库,sql-server,vb.net,Sql Server,Vb.net,我正在尝试连接到非本地的SQL Server数据库。我有数据源和初始目录-没有问题。但需要将集成安全性更改为False并插入SQL Server凭据 有人知道如何将其放入连接字符串中吗 还有,有人知道如何处理SecureStrings吗 以下是我目前的代码: Dim pwd As New SecureString("Password") Dim cred As New SqlCredential("Username", pwd) Dim sql As New SqlConnection("Dat
Dim pwd As New SecureString("Password")
Dim cred As New SqlCredential("Username", pwd)
Dim sql As New SqlConnection("Data Source=OnlineServer;Initial Catalog=DatabaseName;Integrated Security=False")
看看这里:希望找到你需要的。这将为您提供基础知识
要使SQL帐户凭据保密,应加密web.config中的
部分。为此:
aspnet_regiis -pe "connectionStrings" -app "OnlineServer" -prov "DataProtectionConfigurationProvider"
使用ConfigurationManager检索连接字符串将自动解密该字符串
Dim connectionString = ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString
这里有一个更详细的解释。我已经找到了我需要做的事情以及如何处理安全字符串 下面是一段代码片段,供将来遇到困难的人使用:
Imports System.Data.SqlClient
Imports System.Net.Mail
Imports System.Security
Public Module secure
Public Function sql()
Dim pass As String = "Password"
Dim pwd As SecureString = New SecureString()
For Each ch As Char In pass
pwd.AppendChar(ch)
Next
pwd.MakeReadOnly()
Dim cred As New SqlCredential("SQL_Login", pwd)
Dim conn As New SqlConnection("Server=Database_Name;Initial Catalog=Database_Address;Integrated Security=False", cred)
Return conn
End Function
End Module
Public Class sqlCommunications
Dim sql As New SqlConnection
Dim sqlcom As New SqlCommand
Public Sub start()
sql = secure.sql
sqlcom.Connection = sql
sql.Open()
sql.Close()
End Sub
End Class