Sub CreatesqldatabaseMSQL()
Try
Using connect As New DataSchool(GetSQLConnectionString(True))
connect.CreateDatabase()
End Using
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
getsqlconnectionstring此函数返回sqlconnection字符串
Public Function GetSQLConnectionString(ByVal includeDatabase As Boolean) As String
Dim builder As New SqlConnectionStringBuilder()
'Build a connection string from the user input.'
builder.DataSource = Msql.datasource
builder.IntegratedSecurity = Msql.IntSec
If builder.IntegratedSecurity = False Then
builder.UserID = Msql.username
builder.Password = Msql.password
End If
If includeDatabase Then
builder.InitialCatalog = Msql.DatabaseName
End If
Return builder.ConnectionString
End Function
Public Structure Msql
Shared datasource As String
Shared IntSec As Boolean
Shared username As String
Shared password As String
Shared DatabaseName As String
End Structure
1条答案
按热度按时间guicsvcw1#
使用此方法
getsqlconnectionstring此函数返回sqlconnection字符串
msql.server、msql.databasename等这是一个结构,您可以从这里更改数据库名称