开发者

SQL Server 2008 error

开发者 https://www.devze.com 2023-04-11 06:25 出处:网络
I have this code Dim str As String Dim myConn As SqlConnection = New SqlConnection(\"Server=JDBRANDE;Integrated Security=SSPI;Persist Security Info=False\")

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 Sq开发者_高级运维lCommand

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.


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") 


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.


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;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号