Results 1 to 15 of 15

Thread: [RESOLVED] [2005] database table creation issues

Threaded View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Resolved [RESOLVED] [2005] database table creation issues

    i have been searching around and found this thread http://www.vbforums.com/showthread.p...ight=read+.sql which i found interesting and thought I would adopt something like it in my application. only thing is, i get an unhandled exception in my application as soon as it launches. Of course, this information was emailed to me and have all the information. not sure what it means though so thats why I am back. The following form load code is what im using to hopefully execute the sql statements
    vb Code:
    1. Imports System.Data.SqlClient
    2.  
    3. Public Class frmMain
    4.     Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    5.  
    6.         'this directory must exist just incase the application needs to do any SQL creation
    7.         If Not System.IO.Directory.Exists("sql") Then
    8.             My.Computer.FileSystem.CreateDirectory("sql")
    9.         End If
    10.  
    11.         'if there is a file called sql.sql present in the \sql\ directory, execute its content
    12.         With My.Computer.FileSystem
    13.             If System.IO.File.Exists(My.Application.Info.DirectoryPath & "\sql\" & "sql.sql") Then
    14.                 OpenConnectionIfClosed()
    15.                 Dim SQLFile As String = .ReadAllText(My.Application.Info.DirectoryPath & "\sql\" & "sql.sql")
    16.                 Dim sqlCommand As New SqlCommand(SQLFile, m_DBCon)
    17.                 sqlCommand.ExecuteNonQuery()
    18.                 CloseConnectionIfOpen()
    19.                 'now that the request has been completed, delete the file
    20.                 IO.File.Delete(My.Application.Info.DirectoryPath & "\sql\" & "sql.sql")
    21.             End If
    22.         End With
    23.     End Sub
    attached is my sql.sql file (which was exported from my database) --renamed on this thread to .txt because it wouldnt let me upload a .sql file

    the exception/errors that im getting as per my e-mail is:
    An unhandled error has occurred in the application and the error log is attached for resolution assignment.

    Message:
    Incorrect syntax near 'GO'.
    Incorrect syntax near 'GO'.
    Incorrect syntax near 'GO'.
    Incorrect syntax near 'GO'.
    Incorrect syntax near 'dbo'.
    Incorrect syntax near the keyword 'with'. If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon.
    Incorrect syntax near 'GO'.
    Incorrect syntax near 'dbo'.
    Incorrect syntax near the keyword 'with'. If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon.
    Incorrect syntax near 'GO'.
    Incorrect syntax near 'GO'.
    Incorrect syntax near 'GO'.
    Incorrect syntax near 'GO'.
    Incorrect syntax near 'dbo'.
    Incorrect syntax near the keyword 'with'. If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon.
    Incorrect syntax near 'GO'.
    Incorrect syntax near 'GO'.
    Incorrect syntax near 'GO'.
    Incorrect syntax near 'GO'.

    Stack trace:
    at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
    at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
    at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
    at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
    at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async)
    at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
    at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
    at BusinessStudio.frmMain.frmMain_Load(Object sender, EventArgs e) in D:\BusinessStudio\frmMain.vb:line 49
    at System.EventHandler.Invoke(Object sender, EventArgs e)
    at System.Windows.Forms.Form.OnLoad(EventArgs e)
    at System.Windows.Forms.Form.OnCreateControl()
    at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
    at System.Windows.Forms.Control.CreateControl()
    at System.Windows.Forms.Control.WmShowWindow(Message& m)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
    at System.Windows.Forms.ContainerControl.WndProc(Message& m)
    at System.Windows.Forms.Form.WmShowWindow(Message& m)
    at System.Windows.Forms.Form.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    any ideas?
    line 49 (didnt post all the code in the form_load as its not needed) is
    vb Code:
    1. sqlCommand.ExecuteNonQuery()
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width