0

I have a database Linq dbml I need to change the database name before creating

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

Database

Code

5
  • Do you have a connection string for L2S in the config file and/or on the Settings page of the project properties? If so, what is it? Commented Jul 4, 2020 at 3:47
  • "Data Source=LAPTOP-AJM33RB1\TESTSERVER;Integrated Security=True;" this is connectionstring Commented Jul 4, 2020 at 9:57
  • That's the connection string in the code. I asked you whether you had a connection in Settings or in the config file. Are you saying that you do and that it's the same, or did you not answer the question that I actually asked. Commented Jul 4, 2020 at 10:54
  • it's connection string in config file <add name="Hekma_School_Mangment_System.Settings.dtSchoolsConnectionString" connectionString="Data Source=LAPTOP-AJM33RB1\TESTSERVER;Integrated Security=True;" providerName="System.Data.SqlClient" /> Commented Jul 4, 2020 at 11:47
  • What is a DataSchool? Where is its class? Commented Jul 5, 2020 at 0:47

1 Answer 1

1

Use This Method

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 This Function 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 and etc this is Structure, You can change database name From here

 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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.