DB local instance  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

DB local instance

Postby Riyaz » Mon Aug 13, 2018 1:45 pm

Hi Mike

I found the below example on Jiwa documentation for connecting to DB, question is how do I connect to the local jiwa application instance instead of providing server, db name, etc

var manager = new JiwaFinancials.Jiwa.JiwaApplication.Manager();
manager.Logon("MyServer", "JiwaDemo", JiwaFinancials.Jiwa.JiwaODBC.database.AuthenticationModes.JiwaAuthentication, "Admin", password);
manager.BusinessLogicFactory.CreateBusinessLogic<JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder>()null;
var db = manager.Database;
using (SqlCommand SQLCmd = new SqlCommand(sql, db.SQLConnection, db.SQLTransaction))
{
}
Riyaz
Kohai
Kohai
 
Posts: 233
Joined: Wed Dec 02, 2015 2:05 pm
Topics Solved: 2

Re: DB local instance

Postby Scott.Pearce » Mon Aug 13, 2018 2:00 pm

What do you mean by "local jiwa application instance"? If you are referring to localDB, you simply use "(LocalDb)\MSSQLLocalDB" as the server name.
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 742
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 221

Re: DB local instance

Postby Riyaz » Mon Aug 13, 2018 2:04 pm

Hi Scott

What I mean, is that we usually develop plugins on our local instance and then we export and import on to the server instance of our clients, I dont want to edit the plugin and change the database name, username, password etc everytime I do that, so if there is a way where I can connect to the database of jiwa without mentioning user details etc, thats what am after
Riyaz
Kohai
Kohai
 
Posts: 233
Joined: Wed Dec 02, 2015 2:05 pm
Topics Solved: 2

Re: DB local instance

Postby Scott.Pearce » Mon Aug 13, 2018 3:10 pm

Code executing as part of a plugin is already "logged in" to whatever database the plugin resides in. You should not be logging in again via code.
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 742
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 221

Re: DB local instance

Postby Riyaz » Mon Aug 13, 2018 3:30 pm

Thats what I thought, but it gives me the runtime error "The connection property has not been initialized, Module: InvokeMethod",

below is the code used

Dim manager = New JiwaFinancials.Jiwa.JiwaApplication.Manager()

With manager.Database
Try
SQL = "SELECT dbo.IN_Main.Partno, dbo.IN_Main.Description FROM dbo.IN_Main WHERE PartNo = @PartNo ORDER BY PartNo "

Using SQLCmd As SqlCommand = New SqlCommand(SQL, .SQLConnection, .SQLTransaction)
SQLParam = New SqlParameter("@PartNo", System.Data.SqlDbType.Char)
SQLParam.Value = CustomFieldValue.Contents
SQLCmd.Parameters.Add(SQLParam)

SQLReader = .ExecuteReader(SQLCmd)

If SQLReader.Read = True Then
CustomFieldValue.DisplayContents = String.Format("{0} / {1}", .Sanitise(SQLReader, "PartNo"), .Sanitise(SQLReader, "Description"))
End If
End Using

SQLReader.Close()
Finally
If Not SQLReader Is Nothing Then
SQLReader.Close()
End If
End Try

End With
Riyaz
Kohai
Kohai
 
Posts: 233
Joined: Wed Dec 02, 2015 2:05 pm
Topics Solved: 2

Re: DB local instance

Postby Scott.Pearce » Mon Aug 13, 2018 3:32 pm

You should not be new-ing a manager object - there should already be one for you to use that is set up and logged in.

Tell me which version of Jiwa you are using here, and also show me the function in which that code resides.
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 742
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 221

Re: DB local instance

Postby Riyaz » Mon Aug 13, 2018 3:36 pm

Using Jiwa 7.2

Function as below

Public Sub ReadData(ByVal BusinessLogicHost As JiwaApplication.IJiwaBusinessLogic, ByVal GridObject As JiwaApplication.Controls.JiwaGrid, ByVal FormObject As JiwaApplication.IJiwaForm, ByVal Row As Integer, ByVal HostObject As JiwaApplication.IJiwaCustomFieldValues, ByVal CustomField As JiwaApplication.CustomFields.CustomField, ByVal CustomFieldValue As JiwaApplication.CustomFields.CustomFieldValue) Implements JiwaApplication.IJiwaCustomFieldPlugin.ReadData
Dim SQLParam As SqlClient.SqlParameter = Nothing
Dim SQLReader As SqlDataReader = Nothing
If CustomField.PluginCustomField.Name.Trim = "40-SalesPartNo" Then

Dim SQL As String = ""

Dim manager = New JiwaFinancials.Jiwa.JiwaApplication.Manager()

With manager.Database
Try
SQL = "SELECT dbo.IN_Main.Partno, dbo.IN_Main.Description FROM dbo.IN_Main WHERE PartNo = @PartNo ORDER BY PartNo "

Using SQLCmd As SqlCommand = New SqlCommand(SQL, .SQLConnection, .SQLTransaction)
SQLParam = New SqlParameter("@PartNo", System.Data.SqlDbType.Char)
SQLParam.Value = CustomFieldValue.Contents
SQLCmd.Parameters.Add(SQLParam)

SQLReader = .ExecuteReader(SQLCmd)

If SQLReader.Read = True Then
CustomFieldValue.DisplayContents = String.Format("{0} / {1}", .Sanitise(SQLReader, "PartNo"), .Sanitise(SQLReader, "Description"))
End If
End Using

SQLReader.Close()
Finally
If Not SQLReader Is Nothing Then
SQLReader.Close()
End If
End Try

End With
End If
End Sub
Riyaz
Kohai
Kohai
 
Posts: 233
Joined: Wed Dec 02, 2015 2:05 pm
Topics Solved: 2

Re: DB local instance  Topic is solved

Postby Scott.Pearce » Mon Aug 13, 2018 4:02 pm

Every Jiwa object points to a single manager object that was created and configured at log in time. You should use the existing manager object too. It can be accessed via a property that exists as part of most (if not all) Jiwa objects.

So, change your line:

Code: Select all
Dim manager = New JiwaFinancials.Jiwa.JiwaApplication.Manager()


to:

Code: Select all
Dim manager = CustomField.Manager


CustomField was passed into the ReadData() function, and it has a manager property that you can use. Similarly BusinessLogicHost, GridObject, FormObject, HostObject, and CustomFieldValue are passed in - these would all have manager objects accessible for you to use if required.
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 742
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 221

Re: DB local instance

Postby Riyaz » Mon Aug 13, 2018 4:18 pm

Thanks Scott, that worked
Riyaz
Kohai
Kohai
 
Posts: 233
Joined: Wed Dec 02, 2015 2:05 pm
Topics Solved: 2

Re: DB local instance

Postby Scott.Pearce » Mon Aug 13, 2018 4:22 pm

Cool.

Don't forget. Inside a plugin you are already logged in.

7.0.175.0 and earlier only:
Use JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance

7.1 and later only:
Use an existing manager from an existing object (all Jiwa objects have a manager property for you to leverage).
Always use a factory to create new Jiwa objects.
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 742
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 221

Next

Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 20 guests