0

Right now i am modeling a ClientWebPart outside of the SharePoint server. Although, i advised the client to let me on the server to do Code Behind connection, they said not right now. Server might not be ready for developer eyes. :)

That being said, i still need to connect to the Database (on the same Server/Instance) to make sure the Data to be queried will return the way i expect it to.

The only way i saw to do that was to spin up a JavaScript ADODB.Connection/Recordset set of object(s).

Here is what have so far but doesnt seem to be working:

try {
    var rs = new ActiveXObject("ADODB.Recordset");

//      var conn = new ActiveXObject("ADODB.Connection");
} catch (e) {
    alert("ADODB namespace not found.");
    return;
}
var sql = "Select id, value from tblTest";
rs.Open(sql, connStr, adOpenForwardOnly, adLockReadOnly, adCmdText);
//conn.Open(connStr);

lblData = $("#sqlData");
var val = "";

if (conn.State !== adStateOpen) {
    alert("Connection to Server Failed!");
    return;
}

//var rs = new ActiveXObject("ADODB.Recordset");
//rs.Open("Select id, value from tblTest");
rs.MoveFirst

rs.each(function (record, index) {
    val += "id: " + record["id"];
    val += "; value: " + record["value"];
    val += "\n";
});

lbldata.text(val);
//Clean Up
rs.close;
conn.close;

I am open to alternatives. Until i can get to the Server and develop on the SharePoint server, it will have to be client based solution.

Although i am not sure if its possible, i was thinking of doing Embedded coding since the WebParts are nothing but Pages, anyways. But could not find any credible or reliable documentation for SP2013 embedding code in the ASPX file.

Notes

  • Do Not Reference External Content Types as they are resistant to implementation. They are fitting the bill for my time.
  • I know i need to do a WebPart on the Server Side, but they havent given me access to the server so i can develop directly on it.
2
  • Its better that you write an ASP.NET Web Service and call it from JavaScript.. Or you can simply make an Application Page which listens to Ajax Calls.. Mar 20, 2014 at 15:45
  • Do you have anything i can read about loading a WebService into SharePoint? As well, i have done similar implementations with ASP.Net websites where i would have a codebehind page that took in QueryString values and produced JSON for the consuming page to use, but am unsure how to implement that in SharePoint
    – GoldBishop
    Mar 20, 2014 at 16:10

2 Answers 2

1

Personally, I'd host this out of SharePoint as an ASP.net Web API site and enable CORS to the SharePoint site's domain. I've done this sort of thing many times. The idea of embedding SQL commands into JavaScript as strings seems like just begging for some sort of SQL injection to occur.

You could also host the Web API solution in SharePoint. I have never done this, but I would imagine creating a Farm Solution and then adding ASP.net MVC/Web API via nuget would get you started. I might fiddle with this in my free time. If you do this and get it working, you need to write a blog post on it!

2
  • I dont disagree, long term. Right now i need to verify connectivity and functionality of the ClientWebPart. What i use to get the data is irrelevant in the long term. As we will have BCS & ECT implemented.
    – GoldBishop
    Mar 20, 2014 at 18:00
  • Yeah SP2007 and through high modifications SP2010 could be desktop tested and developed. Yeah theres just so much limitation's to Cloud hosting frameworks. You lose control of local implemenations. Secondly, they removed the ability for you to host it locally on your dev machine, unless you have 2008r2 Server, w/SQL Developer Ed, as your dev machine ;). Looking for a good hosting solution for SharePoint but looks like O365 is my suffrage for the time.
    – GoldBishop
    Mar 24, 2014 at 18:35
0

Simple take an Application Page in your solution and implement the Server side methods using System.Web.Services.WebMethod

Let's say you call your Application Page as "AjaxCallsProcessor" and it has a function say "GetSearchResults" than you can use it using JQuery Ajax call as:

$.ajax({
    type: "POST",
    url: "/_layouts/YourSolutionName/AjaxCallsProcessor.aspx/GetSearchResults",
    data: "{'pramater':'" + value + "'}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (response) {
        var serachResults = response.d;
    }
});

You should write all your database connectivity logic on server-end, as the previous answer said there are high chances of SQL Injection otherwise..

3
  • Is there way of "hiding" this page from navigation. Ultimately, it operates as a "ad-hoc service" handler? This i can deal with but as im new to SP2013, i am taking baby steps and not stretching the limites, "For Now" ;)
    – GoldBishop
    Mar 20, 2014 at 18:01
  • How will someone get to something as difficult as "/_layouts/YourSolutionName/AjaxCallsProcessor.aspx".. You may make it more complex :P Mar 20, 2014 at 18:17
  • Im jumping from SP2007 to SP2013 in knowledge. So getting used to the intracacies and peculiarities of this version.
    – GoldBishop
    Mar 21, 2014 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.