I want to truncate database table

I add connection string in following and put it in web.config

<add name="cn" connectionString="data source=10.209.46.210;Initial Catalog=EDWP;User ID=kbanke2e;Password=passw0rd;Persist Security Info=True;Port=5480;Optimize for ASCII=True;" providerName="NZOLEDB"/>

on app.vb I try to coding following to truncate the table but error is populate

Protected Sub Button1_click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
    Dim cnn As String = ConfigurationManager.ConnectionStrings("cn").ConnectionString
    Dim strSQL As String
    strSQL = "TRUNCATE TABLE EDWID02.EXT_RBS_SMN1S00648_1"
    Using connection As New SqlConnection("cnn")

        Dim cmd As New SqlCommand(strSQL, connection)
        cmd.Connection.Open()
        cmd.ExecuteNonQuery()
    End Using

End Sub

The error is below

Format of the initialization string does not conform to specification starting at index 0. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.

Source Error:

Line 12:         Dim strSQL As String
Line 13:         strSQL = "TRUNCATE TABLE EDWID02.EXT_RBS_SMN1S00648_1"
Line 14:         Using connection As New SqlConnection("cnn")
Line 15: 
Line 16:             Dim cmd As New SqlCommand(strSQL, connection)

Upvotes: 0

Views: 895

Answers (1)

John Saunders
John Saunders

Reputation: 161791

Try

Using connection As New SqlConnection(cnn)

You need to supply the actual connection string. You were passing the literal characters "cnn", which are invalid as a connection string, starting at index 0.

Upvotes: 1

Related Questions