Forum Discussion
MarioGV
1 year agoNew Contributor III
how can I close a database connection
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
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.
5 Replies
- DanielWillisValued Contributor
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
- MarioGVNew Contributor III
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
- DanielWillisValued Contributor
I think you might be doing something wrong. Using 'Using' is standard practise. Feel free to share your code.
- Henning
OneStream Employee
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.
- MarioGVNew Contributor III
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.
Related Content
- 1 year ago
- 1 year ago
- 8 months ago
- 6 years ago