Question

  Asked: Dec 16 2007   9:36 PM GMT
  Asked by: Comtrendz


Need help with running an external SQL query from within VB.Net code.


SQL Express, VB.NET, SQL Server errors, SQL Manager

Hi all,
I'm in a bit of a bind and new to SQL.
I have built a DB using the SQL Manager and it works perfectly in my code.
I have used SQL Manager to build the SQL to rebuild my DB as I want to use it in my VB.Net code.

When I execute this SQL in the SQL management studio it works 100 %.

When I execute it in code I get an error: The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. The RPC name is invalid."


All I'm trying to do is build the DB in code. I looked up the error in Google and there was one response which made no sense at all.


DBNew = "Server=" & DBServer & "\SQLEXPRESS;Integrated Security=True;database=master"

Dim objConn As New SqlConnection(DBNew)

Try

objConn.Open()

Catch ex As Exception

MsgBox(ex.Message)

End Try

Dim sr As StreamReader = New StreamReader("C:\Development\PureMatrix\PureMatrix\Scripts\buildDB.sql")

Dim script As String = sr.ReadToEnd

Try

Dim objCmd As New SqlCommand(script, objConn)

MsgBox(script)

objCmd.CommandType = CommandType.StoredProcedure

objCmd.ExecuteNonQuery()

catch

end try

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0



I suspect that this might be a problem sending a unicode string to sql server 2005 driver when it is hoping for an ansi string - assuming the error occurs when you call ExecuteNonQuery

If so, try using System.Text.Encoding.Convert static method to convert to ansi first
  • AddThis Social Bookmark Button

Browse more Questions and Answers on SQL Server and Development.

Looking for relevant SQL Server Whitepapers? Visit the SearchSQLServer.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register