Reputation: 1197
I have this code
Dim str As String
Dim myConn As SqlConnection = New SqlConnection("Server=JDBRANDE;Integrated Security=SSPI;Persist Security Info=False")
Dim myCommand As SqlCommand
Try
myConn.Open()
str = "insert into orders_table(tuid,customer_tuid,start_time,finish_time ) " + " VALUES ('2342', '455', 'NULL', 'NULL')"
'MsgBox(str)
myCommand = New SqlCommand(str, myConn)
myCommand.ExecuteNonQuery()
I keep getting an invalid object name orders_table
error
When I go directly to SQL Server and type in the insert statement, it works.
Upvotes: 2
Views: 186
Reputation: 13265
First, check that JDBRANDE
is definitely the correct server.
If it is, try changing your query to specify a table name:
INSERT INTO my_database.orders_table(tuid,customer_tuid,start_time,finish_time )...
Alternatively, try specifying an Initial Catalog
in the connection string.
EDIT : Example of connection using Initial Catalog
(from http://www.connectionstrings.com)
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;
Upvotes: 0
Reputation: 21
You have not set the database name on the connection string..
Dim myConn As SqlConnection = New SqlConnection("Server=JDBRANDE;Database=DBNameIntegrated Security=SSPI;Persist Security Info=False")
Upvotes: 2
Reputation: 17808
You connection string is either pointing to a database different from the one your manually referring to, one that does not have that table, and/or you've got the name wrong in the sql statement.
Edit - Hmm what the other answers say about missing the schema/initial catalog is most likely your problem.
Upvotes: 1