如何在 Linq 中更改数据库名称 Vb.net
How to Change database name in Linq Vb.net
我有一个数据库 Linq dbml
我需要在创建之前更改数据库名称
Dim dt As New DataSchool()
dt.Connection.Open()
dt.CreateDatabase()
使用这个方法
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 这个函数Return SQLconnection string
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
Msql.Server、Msql.DatabaseName 等这是结构,您可以从这里更改数据库名称
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
我有一个数据库 Linq dbml 我需要在创建之前更改数据库名称
Dim dt As New DataSchool()
dt.Connection.Open()
dt.CreateDatabase()
使用这个方法
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 这个函数Return SQLconnection string
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
Msql.Server、Msql.DatabaseName 等这是结构,您可以从这里更改数据库名称
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