SQL String Connection

Jorge Enciso 116 Reputation points

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.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,899 questions
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,606 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yitzhak Khabinsky 25,206 Reputation points

    Hi JorgeEnciso-6991,

    Please try the following.


    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')"
                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)
                    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. Dan Guzman 9,211 Reputation points

    Connection string values may optionally be enclosed in single or double quotes but not square brackets. There is no need to enclose the database name value in this case:

    Dim conString1 As String = "Data Source=igfnav03; Initial Catalog=Test Navision; integrated Security=true"
    0 comments No comments

  2. Michael Taylor 49,251 Reputation points

    Is igfnav03 a SQL Server instance on your local machine or the network?

    Is Windows auth enabled on the SQL Server?

    In SSMS does it show that your user account has permissions to access the Test Navision database?

    Your tag includes Azure SQL. To connect to SQL Azure using Win auth you have to properly enable AD integration (which requires infrastructure support) and you must use AAD integration.

    0 comments No comments

  3. Jorge Enciso 116 Reputation points

    Without brakets have this error:
    System.Data.SqlClient.SqlException: 'Incorrect syntax near '`'.
    Unclosed quotation mark after the character string ' '.'

    Network server
    Windows Auth. enables in SQL Server
    Have Permissions to access Test Navision

    Now here is the thing:
    If I made a new dbconnection in VS2019 and use Windows Ath it works no problem but if i do SQL Auth have same error.

    Thank you for the responds........
    TAG was a mistake no AZURE at all.

  4. Seeya Xi-MSFT 16,451 Reputation points

    Hi @Jorge Enciso ,

    Did you set this:

    Best regards,

    If the response is helpful, please click "Accept Answer" and upvote it, as this could help other community members looking for similar queries.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.