1. Arcady Abramov
  2. Beta Testing
  3. Wednesday, 22 January 2020 11:43 AM UTC

Hello, team

In PB classic we used function ds.setTransObject(sqlca) all the time. 

I assumed that the parallel use in SnapDevelop would be SetDateContext, but it now says that this function is obsolete and will be deprecated and simple assignment should be used instead.

In PB classic, if the transaction object was not valid (not connected, for instance) we would get an error. Is there a way to receive the same error before any DB operations are attempted?

 

Thank you

Arcady

Logan Liu @Appeon Accepted Answer Pending Moderation
  1. Thursday, 23 January 2020 05:40 AM UTC
  2. Beta Testing
  3. # 1

Hi Arcady,

1) "I assumed that the parallel use in SnapDevelop would be SetDataContext, but it now says that this function is obsolete and will be deprecated and simple assignment should be used instead."

Please set ds.DataContext property instead of calling ds.SetDataContext() method.

Notice that SnapObjects connect to the database only when needed by default. It's not similar to PB.

2) "Is there a way to receive the same error before any DB operations are attempted?"

SnapObjects will throw exceptions when any database error occurs, instead of using the traditional way in PB to catch Database errors and return them to an event or return an error code. Exceptions ensure that failures do not go unnoticed because calling code didn't check a return code.

Refer to .NET document for more details:

https://docs.microsoft.com/en-us/dotnet/standard/exceptions/#exceptions-vs-traditional-error-handling-methods

Regards,

Logan

Comment
  1. Arcady Abramov
  2. Thursday, 23 January 2020 05:47 AM UTC
I need to better understand how connection to DB works.

If PS script code has 3 embedded SQLs one after another, does this mean that the .NET code will connect to the DB 3 times?

Is there a way to keep this connection open and close it manually when required?
  1. Helpful
  1. Logan Liu @Appeon
  2. Friday, 24 January 2020 05:11 AM UTC
Hi Arcady,

We are using ADO.NET to connect to DB. Connecting to a data source can be time-consuming. To minimize the cost of opening connections, ADO.NET uses an optimization technique called connection pooling, which minimizes the cost of repeatedly opening and closing connections.

Refer to https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/connection-pooling for more details.



If you want to keep this connection open and close it manually, please call DataContext.CurrentConnection.Open() and DataContext.CurrentConnection.Close().

Regards, Logan
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.