2015-06-11 47 views
0

我在下面添加連接字符串,並把它在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"/> 

上app.vb我嘗試編碼以下截斷表,但是錯誤是填充

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 

誤差低於

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) 
+2

嘖嘖,只要有辦法知道錯誤是什麼,你提了。如果只有某個實際上看過它的人可以告訴我們錯誤信息是什麼以及還提供了其他任何信息。 – jmcilhinney

+0

我加了這個編程的錯誤 –

+0

我當然希望這不是真正的用戶名和密碼。 – vesan

回答

1

嘗試

Using connection As New SqlConnection(cnn) 

您需要提供實際的連接字符串。您是通過文字字符「CNN」,這是無效的,因爲一個連接字符串,開始在索引0

+0

這似乎是正確的,但我不確定即使那樣,代碼也能正常工作。這似乎是Netezza DBMS的OLE DB連接字符串,但OP正在創建一個僅用於SQL Server的「SqlConnection」對象。我認爲OP需要切換到使用'OleDb'而不是'SqlClient'。 – jmcilhinney