How to connect K2 blackpearl with MS SQL R2?

  • 19 April 2012
  • 5 replies
  • 2 views

Badge +2

Can somebody please tell me how to go about doing this? How do we connect the MS SQL server to the K2 blackpearl environment??


I have created a smart object called Employee. It contains Employee ID, Domain Name. I have created a table in SQL server that contains EmployeeID, Domain Name and EmployeeName. How do i connect the two? How do i retrieve the Domain Name based on the Employee ID through Smart Object?


It will be of GREAT help to let me know this. I'm extremely new to K2 and would really appreciate the help!! :-)


Thanks


Sravanthi


5 replies

Badge +10

Hi,


You need to configure the SQL Server Service Instance to point to your database using the SmartObject Service Tester found in your K2 blackpearlBin folder. Create a new Service Instance and specify the necessary parameters to have it connect to your DB.


After you have done this go back to your SmartObject and delete the default SmartBox methods. Switch the designer to Advanced mode and add a new method. Browse for the new Service Instance you have created and select the table you want to connect to and the relevant method. Next configure and bind all the properties. Repeat this for all methods you require and then save and deploy your SmartObject.


There is a shortcut from the SmartObject Service Tester to create a SmartObject directly after the Service Instance has been created. In the Service Instance expand to your table, right-click it and click on "Create SmartObject". This will create and publish a SmartObject exposing all the properties and methods of your SQL table and you can immediately test it by navigating to the actual SmartObject and executing a method.


I think there might be some help in the K2 Documentation, check that out as well.


Hope this helps!

Badge +9


Welcome to the K2 forum!


 


The steps provided by Johan is correct and will work when
you have existing SQL DB with tables that you want to expose as K2 SmartObjects,
however it sounds like you are creating the SQL DB and Tables manually and then
want to link that with K2 SmartObjects, this is not needed as K2 provides a way
out of the box to create new SmartObjects from scratch the end result being a Table
on your existing SQL Server. I will explain the easy way that will safe you
some time by cutting back on a number of manual steps.


 


For this example let continue using Employee, follow the
steps below:


-         
Open K2 Studio by clicking Start > K2 blackpearl
> K2 Studio


-         
Create a new K2 Project by clicking File >
New, from K2 Type select K2 SmartObject. At the bottom of the screen rename
SmartObject to Employee and click create.


-         
Now in K2 Studio you should see (In Solution Explorer)
K2Project1 and under that your K2 SmartObject called Employee, on the right you
can now start to define the properties you need for your SmartObject


-         
From the Ribbon locate the Add icon under the properties
section and click it, in the Add SmartObject Properties dialog go ahead and
create the following properties


o   Employee
ID (you can make this a auto number of leave this as Text)


Important: Select this as
your Key field


o   Domain
Name


o   First
Name


o   Last
Name


o   Email


Feel free to add additional properties
if you need them


-         
Once done with adding properties click OK


-         
Review the properties and if you are happy you
can go ahead and deploy your Employee SmartObject by clicking the Deploy button
from the Ribbon on the Home tab


 


This will do the following, create the Employee SmartObject
and also create  table in SQL where you
can store the data related to your employee SmartObject


 


You can open SQL Management Studio and once logged in check
under Databases you will find  a Database
called K2SmartBox, expand this and under Tables you will find a newly created Employee
table, open this table and you will find it created all the field you specified
for your SmartObject


 


At this point you can go ahead and add some records or you
can do this using a K2 utility that allows you to test your SmartObjects


 


To test your Employee SmartObject follow the steps:


-         
Open windows explorer and brows to C:Program
Files (x86)K2 blackpearlBinSmartObject Service Tester.exe


-         
Once open, expand the SmartObject Explorer node,
you should see a folder called K2Project1 (assuming you did not rename the K2
Project created in the steps above), expand the folder and under that you
should see your Employee SmartObject


-         
Right click on the Employee SmartObject and
select Execute SmartObject


-         
From the Method to execute dropdown select
Create, fill out some info for your employee and click Execute to create the
employee record


Repeat this step if you want to create multiple
Employees


-         
Once you have a couple you can change the Method
to execute to Get List and hit execute to get a list of employees created


-         
Using the Load method you can load a specific
employee provided you know the corresponding ID or you can use the Get List
method and provide some of the properties as an example Name or even Domain Name
and hit execute, this will return all records matching the input info you have
provided


 


Let me know if these steps helped you to get going, if not
please give me a shout with your questions and we can take it further


Badge +2

Hello Johan and Renier :)


Thanks a million for all the help! :) I've been working with this only from the past week and progress has been painfully slow. After going through both your posts, i feel i'm moving :)


I had asked how the database and K2 are connected. I figured it out through the K2Smartbox. Not i have more queries regarding these :)


Renier,


Thank you very much for the detailed step-by-step explanation. I completed whatever u have given without any hassle and it was amazing to finally get some output! :)


With your example, i could connect the database with smart object.


Thank you :)


My next step was to figure out how to get smart objects from database without creating them. Johan has helped me out there :)


Johan,


I'm assuming that if i complete whatever u've said, i would achieve what i want. But, i'm stuck. I did create a database called "TKTCTest". Its connected to a database.


So in the SmartObject Service Tester, i registered a new Service Instance giving the databse name i created and the server name etc. The connection was successful.I created the smart object from the "all smart objects" part. I created a .sodx from it. I added it to a K2 solution to further use it. So i successfully created a smartobject from the database. :)


 My doubt is that, despite me not creating any methods for the smart object, i get only List method as the default method. Why is that?


Also, to create new methods, i have no idea how to configure input parameters and configure "Add service object method".


Thank you Johan:)


Renier and Johan,


It would be really helpful if i get a small tutorial as to how to add these methods :)


Thanks a LOT guys :D


Help much apprecited! :) :)


 


Sravanthi :)

Badge +10

Hi,


The SQL Service instance works in such a way that it only gives list methods if your tables do not have primary keys defined. I would suggest that you add a primary key to your table and refresh your service instance using the SmartObject Service Tester and then recreate your SmartObject. You should find that all the methods will be available. You will also find that these methods will have the input properties correctly defined.


Please give this a try and let us know whether it resolved your problem.


Regards,

Badge +2

Hey Johan! :)


I did create a primary key for my table and created a SmartObject from that. I got Create and Load as the two extra methods. What about the other two methods that we get as default i.e. Save and Delete?


Also, when a smartobject is created from the database like i am doing, i am not able to see the service type. When a smartobject is created from smartobject project in Visual Studio, the service is SmartBox Service. Of course i have used the SQL Server Service to create a smartobject from an existing database, so can i assume that the service is the same?


Anyway, i haven't much clue about how knowing the service is going to help me either! :P


Thank You


Sravanthi :)

Reply