Not inserting into SQL

tehon3299

Well-known member
Joined
Jan 6, 2003
Messages
155
Location
Liverpool, NY
This is my code:
Code:
		Sub UpdateDB()
			Dim MyCommand As New SqlCommand
			Dim MyConnection As New SqlConnection
			Dim MySQLDataAdapter as New SqlDataAdapter
			Dim SessionCmd As String
			Dim File as String
			File = Session("sFileName")
			
			MyConnection = New SqlConnection("server=(local);database=SongShare;Trusted_Connection=yes")

			SessionCmd = "INSERT INTO tmSongs FileName VALUES (" & File & ")"
			
			MyCommand = New SqlCommand(SessionCmd, MyConnection)
		End Sub

I am calling this function by saying UpdateDB() and for some reason its not putting anything in my SQL table. I am putting the filename is a session variable in a global.asax. Whats wrong with this code??
 
youre never actually executing the command in this code. youd need to call MyCommand.ExecuteNonQuery() or add the MyCommand as your InsertCommand property of the dataadapter and call its Update() command. Shouldnt FileName be in parens after tmSongs too?
 
Thanks quwiltw I just noticed that. Now I get a

"Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached."

Whats this all about? I have about 800 enties going into this database.
 
Here ya go:
Code:
		Sub UpdateDB()
			Dim MyCommand As New SqlCommand
			Dim MyConnection As New SqlConnection
			Dim MySQLDataAdapter as New SqlDataAdapter
			Dim SessionCmd As String
			Dim File as String
			File = Session("sFileName")
			
			MyConnection = New SqlConnection("server=(local);database=SongShare;Trusted_Connection=yes")

			SessionCmd = "INSERT INTO tmSongs (FileName) VALUES (" & File & ")"
			
			MyCommand = New SqlCommand(SessionCmd, MyConnection)
			
			MyCommand.Connection.Open()
					
			Try
				MyCommand.ExecuteNonQuery()
			Catch Exp As SQLException
				If Exp.Number = 2627
			        
				Else
			        
				End If
			End Try

MyCommand.Connection.Close()
		End Sub

Thanks
 
I have figured out that its getting to the ELSE inside of the CATCH. Its error number 128. What is that?
 
Last edited by a moderator:
OK...I think there is something wrong with the insert because if it comes to a number to insert it will but once it gets for letters it bombs.
 
Its not taking the whole string into the INSERT statement because I have the word break as something that Im inserting into the table and it thinks im trying to break from a loop.
 
Back
Top