diff --git a/src/dotnet/Vectorization/Services/ContentSources/AzureSQLDatabaseContentSourceService.cs b/src/dotnet/Vectorization/Services/ContentSources/AzureSQLDatabaseContentSourceService.cs index 1caf53be45..4dcf1e24a0 100644 --- a/src/dotnet/Vectorization/Services/ContentSources/AzureSQLDatabaseContentSourceService.cs +++ b/src/dotnet/Vectorization/Services/ContentSources/AzureSQLDatabaseContentSourceService.cs @@ -57,23 +57,30 @@ private async Task GetBinaryContent(string schema, string tableName, { try { - using (SqlConnection connection = new SqlConnection(_settings.ConnectionString)) + using (var connection = new SqlConnection(_settings.ConnectionString)) { await connection.OpenAsync(cancellationToken); - using (SqlCommand command = new SqlCommand($"SELECT TOP 1 {contentColumnName} FROM [{schema}].[{tableName}] WHERE {identifierColumnName} = `{identifierValue}`", connection)) + // WARNING! This is for experimentation purposes only as it is not injection-safe! + // TODO: More work to sanitize and add safety layers against injection. + + using (var command = new SqlCommand($"SELECT TOP 1 {contentColumnName} FROM [{schema}].[{tableName}] WHERE {identifierColumnName} = @identifierValue", connection)) { - using (SqlDataReader reader = await command.ExecuteReaderAsync(cancellationToken)) + command.Parameters.Add(new SqlParameter("@identifierValue", identifierValue)); + + using (var reader = await command.ExecuteReaderAsync(cancellationToken)) { + if (!reader.HasRows) + throw new VectorizationException($"The file {identifierValue} was not found in the database."); await reader.ReadAsync(); return new BinaryData(reader[contentColumnName]); } } } } - catch + catch (Exception ex) { - throw new VectorizationException($"Error when extracting content from file identified by {identifierValue} in Azure SQL Database."); + throw new VectorizationException($"Error when extracting content from file identified by {identifierValue} in Azure SQL Database.", ex); } } } diff --git a/src/dotnet/VectorizationAPI/VectorizationAPI.csproj b/src/dotnet/VectorizationAPI/VectorizationAPI.csproj index fb544ce400..0d9a773b7c 100644 --- a/src/dotnet/VectorizationAPI/VectorizationAPI.csproj +++ b/src/dotnet/VectorizationAPI/VectorizationAPI.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - true + false 35b5c460-a49c-4185-a169-676d90673146 FoundationaLLM.Vectorization.API FoundationaLLM.Vectorization.API