Skip to main content
December 9, 2024
Solved

how can I close a database connection

  • December 9, 2024
  • 3 replies
  • 0 views

cHi All, good day.

 

I'm using a database connection and it's working good:

Dim dt As DataTable = Nothing 
Dim dbConnApp As DbConnInfo = BRApi.Database.CreateDbConnInfo(_si, Dblocation.External, "OneStream BI Blend")
Dim stringSQL As String= "SELECT Entity,UD1_01,UD1_02,UD1_03,UD1_04,UD1_05,UD1_06,UD1_07,UD1_08,UD1_09,UD1_10,UD1_11,UD1_12,UD1_13,UD1_14,UD1_15 from XFC_UD1sbyEnt where Entity = " & "'" & api.Pov.Entity.Name & "' ; "

dt  = BRapi.Database.ExecuteSql(dbConnApp, stringSQL.ToString, False)

but in the error message log have a lot of messages that I need to close the connection

Summary: Error in DbConnInfo.~DbConnInfo(). DbConnInfo should be used in a 'using' statement or Close() should be called explicitly.

 

does someone know how should be the command for close the connection?

 

Thanks in advance and best Regards.

Mario Guerrero

Best answer by MarioGV

hi All, after several tests and SQL readings, I found the solution, at the end it need to add a line:

            dbConnApp.Close()

The database connection has closed and no error message.

I hope it could help somebody. Regards.

3 replies

Employee
December 9, 2024

Hi Mario

The Snippets panel has a lot of information for things like this. The error message is pointing you to the Using statement which automatically closes the connection when done.



Regards,

Daniel

MarioGVAuthor
December 9, 2024

Hi Daniel, it suppose to close the connection, but in the error log shows more than 100 pages with the same error message and it's difficult to track other messages. when I found the solution will let you know.



Thank you for your comment. Regards.

Mario Guerrero

Employee
December 10, 2024

I think you might be doing something wrong. Using 'Using' is standard practise. Feel free to share your code.

December 11, 2024

I would also recommended to follow standard practice on that and try to use the "Using" statement as e.g. per snippet Daniel shared earlier.

MarioGVAuthorAnswer
December 10, 2024

hi All, after several tests and SQL readings, I found the solution, at the end it need to add a line:

            dbConnApp.Close()

The database connection has closed and no error message.

I hope it could help somebody. Regards.