如何在linqvb.net中更改数据库名称

of1yzvn4  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(303)

我有一个数据库linqdbml,我需要在创建之前更改数据库名称

Dim dt As New DataSchool()
  dt.Connection.Open()
  dt.CreateDatabase()


guicsvcw

guicsvcw1#

使用此方法

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

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

相关问题