0

I have a VB.NET application that has 2 routines to open databases in SQL which all worked fine until we migrated databases to an SQL Azure Instance with MFA.

The first sequence works fine with MFA and gets authenticated to show the list of databases to choose from. However, when i pick the database from the selection in the application, i cannot get the MFA prompt to authenticate again

Any help appreciated

Private connection2 As SqlConnection
    Private Sub ImageComboBoxDatabase_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ImageComboBoxDatabase.SelectedIndexChanged

        TreeList1.Visible = False
        WindowsIdentity.GetCurrent()

        Dim listDataBases As New List(Of String)()
        server = ImageComboBoxDatabase.EditValue.ToString
        Dim connectString As String = "Data Source=" & server & " ; Authentication=Active Directory Interactive; Encrypt=True; Initial Catalog=master; User Id=" & User


        connection2 = New SqlConnection(connectString) ' Store the connection
        connection2.Open()

        Dim selectSQL As String = "Select name from sys.databases where name Like 'cw_%';"

        'Using con As New SqlConnection(connectString)

        Using com As New SqlCommand(selectSQL, connection2)
            Using dr As SqlDataReader = com.ExecuteReader()
                While dr.Read()
                    listDataBases.Add(dr(0).ToString())
                End While
            End Using
        End Using

        GridLookUpEditDropDown.Properties.DataSource = listDataBases        
    End Sub
Public Cnstring As String
Private connection As New SqlConnection(Cnstring)

Private Sub SimpleButtonProjectSwitch_Click(sender As Object, e As EventArgs) Handles SimpleButtonProjectSwitch.Click
          
          
            CnString = "Data Source=" & server & " ; Authentication=Active Directory Interactive; Encrypt=True; Initial Catalog=master; User Id=" & UserNameVariable
            
            'Treelist
            TreeListTableAdapter.Connection.ConnectionString = Cnstring
Me.TreeListTableAdapter.Fill(Me.Ds_TreeList.TreeList)
    End Sub

I can get it to work if i use an SQL Login username but not an authenticated user which i need

13
  • How do i keep the first connection open and use it for the second routine ? Commented Apr 23, 2024 at 12:58
  • You mean to say you want to use MFA for first time assignment and then it should not ask for login or MFA again? Commented Apr 25, 2024 at 12:35
  • 1
    Yes, i'd like the first connection to continue Commented Apr 26, 2024 at 12:56
  • Do i need to get an Access token ? Commented Apr 27, 2024 at 12:42
  • 1
    github.com/sullman1/Sullman1Test Commented Apr 27, 2024 at 16:05

0

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.