SQL String Connection

Jorge Enciso 116 Reputation points
2021-08-25T14:47:15.523+00:00

My Connection String:
Dim conString1 As String = "Data Source=igfnav03; Initial Catalog=[Test Navision]; integrated Security=true"

Error in Program:
System.Data.SqlClient.SqlException: 'Cannot open database "[Test Navision]" requested by the login. The login failed.
Login failed for user 'GOURMETFOODS\jenciso'.'

Error in SQL:

Error: 18456, Severity: 14, State: 38.

Developer technologies | VB
SQL Server | Other
0 comments No comments
{count} votes

Answer accepted by question author
  1. Yitzhak Khabinsky 27,091 Reputation points
    2021-08-30T18:37:33.627+00:00

    Hi JorgeEnciso-6991,

    Please try the following.

    VB.NET

    Sub Main
        Const FILENAME As String = "e:\temp\file_ADO.NET.VB.xml"
    
        Dim builder As SqlConnectionStringBuilder = New SqlConnectionStringBuilder()
        builder.DataSource = "SPACESHIP,1433"
        builder.InitialCatalog = "AdventureWorks2012"
        builder.IntegratedSecurity = True
        builder.ApplicationName = "Wonderful application"
        builder.NetworkLibrary = "dbmssocn"
        builder.PacketSize = 32768
    
        Using con As SqlConnection = New SqlConnection(builder.ConnectionString)
            Using cmd As SqlCommand = New SqlCommand()
                cmd.Connection = con
                cmd.CommandType = CommandType.Text
                cmd.CommandText = "SELECT TOP(2) * FROM Person.Person FOR XML PATH('r'), TYPE, ROOT('root')"
                con.Open()
    
                Using reader As XmlReader = cmd.ExecuteXmlReader()
                    Dim xdoc As XDocument = XDocument.Load(reader)
                    Dim settings = New XmlWriterSettings()
                    settings.Indent = True
                    settings.OmitXmlDeclaration = False
                    settings.IndentChars = Microsoft.VisualBasic.Constants.vbTab
                    settings.Encoding = New UTF8Encoding(False)
    
                    Using writer = XmlWriter.Create(FILENAME, settings)
                        xdoc.Save(writer)
                    End Using
                End Using
    
                Console.WriteLine("File '{0}' has been created.", FILENAME)
            End Using
        End Using
    End Sub
    
    0 comments No comments

18 additional answers

Sort by: Most helpful
  1. Jorge Enciso 116 Reputation points
    2021-08-30T18:26:26.907+00:00

    Visual Basic doesn't recognize the command:
    SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder()

    0 comments No comments

  2. Jorge Enciso 116 Reputation points
    2021-08-30T19:26:50.527+00:00

    YitzhakKhabinsky-0887

    Thank you so much!!!!!!!!!
    works perfectly.

    also thanks everyone who help me in this mater with the posts, I really appreciate the help.......

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.