Product Documentation

FairCom C# Stored Procedures

Previous Topic

Next Topic

Tutorials for .NET Stored Procedures

A solution file that contains two tutorial projects (which follow our standard FairCom tutorial model) is provided in:

drivers\csharp.sql.storedprocs\tutorials\Tutorials.sln

This solution file works in Visual Studio 2012, 2015, 2017 and 2019.

To use the tutorials, first double-click on the solution file drivers\csharp.sql.storedprocs\tutorials\Tutorials.sln to load it into Visual Studio.

If Visual Studio reports that the solution file is incompatible, it is likely that the Stored Procedure Extension has not been installed into Visual Studio yet. Please refer to the previous section of this document for instructions on installing that extension.

Unlike our other tutorials, this tutorial has just one solution file for all of the supported versions of Visual Studio. If you see the following window while the solution is being loaded, click the OK button.

If you see the following window, click Reload All:

At this point, the “Tutorials” solution and project should be completely loaded into Visual Studio. Select Build > Rebuild Solution to build the project.

Once the build has succeeded, right-click on the first tutorial (tutorial_1.cs) inside the Stored_Procedures folder in the Solution Explorer and select Deploy to Server.

If the deploy fails (“Not able to connect to server - No connection could be made…”), be sure the c-tree server is still running.

  • Remember that the evaluation license times out and shuts down the server every 3 hours.
  • If you get a message saying the stored procedure already exists in the c-tree server database, click OK to update the server with your new build.

Once the deploy has succeeded, you can test it by right-clicking on it in the Solution Explorer again and choosing Test Procedure. This should produce a pop-up window similar to the following:

Again, if you get a “"Not able to connect to the c-tree server” message, be sure the c-tree server is running.

Put a check mark in the Commit transaction control to force a transaction commit after the Stored Procedure exits. Remember that it is not possible to handle transactions inside a stored procedure itself.

Click the Execute button and the ResultSet control should be populated with rows from the c-tree database:

You can then test the other tutorial (tutorial_2.cs) in the same way: First deploy it to the server, then test it. The second tutorial produces a different ResultSet.

Feel free to browse the source code of the tutorials to see how they work. The procedure that is called when you test the procedure is the ExecuteSP() function, which is at the bottom of each of the tutorial files.

In This Chapter

Writing .NET SP, UDF, and Triggers

Writing a New SP, UDF, or Trigger

Deploying, Testing, and Debugging

Altering the SP, UDF, or Trigger

Writing the Code

Returning Results

Accessing Old and New Rows in Triggers

TOCIndex