我有一个程序通过存储过程从数据库中获取值。它的作用是获取值,下载图像然后将其上传到服务器。上传后运行另一个存储过程只是为了将表更新为新的URL。
现在它上传了一些正确的图像然后突然间它使我的ID =“”而我无法理解为什么?
结果为日志文件:
Property ID : 29140
pk_photo_id (TRY): 47334070
- File : propimage29140_9.jpg has been uploaded to AWS S3 bucket: ruans
Property ID : 30402
pk_photo_id (TRY): 47174447
Property ID : 29330
Property ID : `<-- why make it nothing`
pk_photo_id (TRY): 47174392
ERROR 6 : Cannot insert duplicate key row in object 'dbo.ET_EXPORT_PROPERTY_QUEUE' with unique index 'idx_pk'. The duplicate key value is (<NULL>).
The statement has been terminated.
我的VB sub发生了这种情况:
Dim files As String() = Directory.GetFiles(txtFolderPath)
'for each image get file name
For Each images As String In files
Dim id As String = ""
Dim photoID As String = ""
Dim position As String = ""
For Each str As String In IDS
If Path.GetFileNameWithoutExtension(sKey).Contains(str) Then
id = str
End If
Log("Property ID" & id)
For Each value As String In PhotoIDS
photoID = value
Next
For Each URL As String In fullURL
fullURLIndex = URL
Next
Next
'AWS upload
Try
utility.Upload(txtFolderPath & sKey, bucket)
Catch
needsToExitSub = True
Dim cmdSetError As New SqlCommand("ETSP_UPDATE_PHOTO_URLS")
cmdSetError.CommandType = CommandType.StoredProcedure
cmdSetError.Parameters.AddWithValue("@stype", "L")
cmdSetError.Parameters.AddWithValue("@surl", fullURLIndex)
cmdSetError.Parameters.AddWithValue("@status", 3)
cmdSetError.Parameters.AddWithValue("@pk_photo_id", photoID)
Log("pk_photo_id (CATCH): " & photoID)
cmdSetError.Parameters.AddWithValue("@bactive", 1)
cmdSetError.Parameters.AddWithValue("@property_id", id)
cmdSetError.Parameters.AddWithValue("@client_id", clientIDs)
conn.Open()
cmdSetError.Connection = conn
cmdSetError.ExecuteNonQuery()
Log(" - ERROR 4 : File : " & sKey & " Image ID : " & photoID & " Has NOT been uploaded to " & bucket & " , URL: " & fullURLIndex)
conn.Close()
If needsToExitSub = True Then
Exit Sub
End If
End Try
'Make files public - check this
Dim cannedACL As S3CannedACL = S3CannedACL.PublicRead
Dim fileNameOnly As String = Path.GetFileNameWithoutExtension(sKey)
Dim token As String = fileNameOnly.Remove(fileNameOnly.LastIndexOf("_"c))
Dim number As New String(token.SkipWhile(AddressOf [Char].IsLetter).ToArray())
'Run stored procudure and update if uploaded
Dim cmdSet As New SqlCommand("ETSP_UPDATE_PHOTO_URLS")
cmdSet.CommandType = CommandType.StoredProcedure
cmdSet.Parameters.AddWithValue("@stype", "L")
cmdSet.Parameters.AddWithValue("@surl", Convert.ToString("www.url.com/" & bucket & "/" & sKey))
cmdSet.Parameters.AddWithValue("@status", 2)
cmdSet.Parameters.AddWithValue("@pk_photo_id", photoID)
Log("pk_photo_id (TRY): " & photoID)
cmdSet.Parameters.AddWithValue("@bactive", 1)
cmdSet.Parameters.AddWithValue("@property_id", id)
cmdSet.Parameters.AddWithValue("@client_id", clientIDs)
conn.Open()
cmdSet.Connection = conn
cmdSet.ExecuteNonQuery()
conn.Close()
Next
Log(" - File : " & sKey & " has been uploaded to AWS S3 bucket: " & bucket)
Catch ex As System.NullReferenceException
Log("ERROR 5 : " & ex.Message)
Catch ex As Exception
Log("ERROR 6 : " & ex.Message)
Exit Try
End Try
因此图像将文件下载到我的计算机中的正确文件夹中,然后将其上传到正确的文件夹,但是当更新数据库以更新新的URL时,其他参数会给出错误,现在我认为这是因为Property ID :
为空。
为什么它会得到正确的Property ID :
让我们说8张图片然后得到一段时间的空值然后再次得到正确的Property ID :
。以及如何解决这个问题。
C#help welcome