SQL azure k2
When you want to communicate with a SQL Azure database using K2, it can easily be achieved by following the steps below once you have an SQL Azure database in place –
- Create a Class Library Project in Visual Studio
- Navigate to File.
- Navigate to New
- Click New Project
- Search for the Class Library Project
K2 Automated Testing Software
BenchQA allows full test automation of K2, including fully automated K2 SmartForms and K2 Workflow testing. It promotes test driven development for K2 and ensures continued quality assurance for K2 solutions. Easily apply changes to test cases to accommodate changes to K2 apps and ensure all apps are regression tested to avoid defects and assure continuous quality.
- Name the project and click OK
Your Class library project should be created now and the Project should look like this.
Delete the Class named “Class1”
- Create the ServiceBroker Class to register the project in K2
- Create a New Class with the name “ServiceBroker”
- Add the “K2ServiceBroker” from nuget
- inherit from the : ServiceAssemblyBase
- Override the GetConfigSection Method
- Add the 2 Configs you need to communicate with the Azure Database
The 2 config sections below are the necessary information required to connect to the Azure Server.
- End Point
- Azure Connection String
The steps that we followed up to this point were to create and register a K2 Service Broker.
- Create the class that does the Actual Work
- Create The class named “AzureBlobService”
- Add the Attributes ServiceObject To the AzureBlobService (this is just the name and description of the service in the TesterTool of k2 that would be displayed)
- Add an Empty Constructor into the AzureBlobService and the Following Properties :
- And then we add 3 More Properties. These properties is just an Example
The Attribute Above the properties specifies the Actual Property for K2. Now that we added the Properties, we can continue to the Actual Method to call from K2.
- Create a Method Named “Create”
K2 sees the Create method like this:
Create(FileDate ,FileName,FilePath)
Instead of just passing the variables into the method, K2 sets the Properties and you can use the properties.
Now before you can do any work on the Azure database, you have to connect to the database.
- Connecting to the Azure Database inside the Create Method:
- Add the Reference “WindowsAzure.Storage” from Nuget
- Add the Following Code to Connect to the Azure Database
- Now the first section gets the Connection String from the Configuration Section
- The second section created the actual connection as a client to azure to communicate with the database
- Then it gets the reference Container
- And if it doesn’t exists, it is created the container.
You method should now look like this –
Now you just register the dll as a K2 Service Broker, the communication to the Azure database is done and the implementation of the method is up to the reader.