Hi Jeff,
The database called SR’s collection called EmailUs stores webmail from users. Stored data include messages from users ands replies from our staff, so in addition to email-message date and sender’s email address, a composite key is included to group each email in the thread, composed of the sender’s email address and a 64-bit integer (representing milliseconds since Jan 1 1970) taken from their first email in the grouping. Thus the system should be able to retrieve all emails belonging to a specific thread, ordered by date sent and, marked as either originating from the user or from staff.
Is my understanding correct that you wanted to query data from a MongoDB server using a SQL Server stored procedure written in C#?
1) My preferred method: Read data SYNCHRONOUSLY (not sure how) from CLR SQL assemblies developed in Visual Studio 2012, and integrate with data from Sql Server
You may find some examples in the Quick Tour page under the heading “Query the Collection”. There are examples for querying a collection using synchronous and asynchronous methods.
2) Not my obvious choice: Read data from C# code on IIS 7.5 web server, developed in Visual Studio 2008 (.Net v.2.0), and integrate with records retrieved from Sql Server sproc
Please note that .NET 2.0 is not supported by MongoDB C# driver. The lowest .NET version supported by the C# driver is .NET 3.5, and the latest C# driver requires .NET version 4.5.
An alternative solution could be using a REST-style API layer in front of the MongoDB server, and perform queries on the MongoDB database using REST instead of using a driver. Examples of REST interfaces can be found in the HTTP Interface page.
Regarding your issues:
1) NuGet will not reference MongoDB drivers in CLR SQL assemblies in Visual Studio 2012
I believe Nuget is not supported for CLR SQL assembly. You would have to add the dll files manually in the project.
2) I find legacy drivers documentation very confusing
Please let us know which page you find confusing, as there may be room for improvements in the documentation.
3) I prefer to retrieve all records as a JSON array in a string variable, and without MongoDB’s “id” field, as it will need to be removed.
You can find an example in the Quick Tour page, under the section labeled Projecting Fields . The example describes how to exclude the _id
field from query result.
4) Note from the attached image, a problem exists with the two await statements. I wonder if changing to a synchronous read will resolve the issue.
As mentioned in the await reference page: “The asynchronous method in which await
is used must be modified by the async
keyword”. I.e., the ViewThread
method must be changed to public static async <return type> ViewThread(...)
. You can find some synchronous and asynchronous query examples in the Quick Tour page that you can follow.
You may find these links useful for your case:
If you have time, I would recommend you to enroll in the M101N: MongoDB for .NET Developers online course for an in-depth introduction to MongoDB and the C# driver. It is a free course, and the next one will start at May 24 2016.
Best regards,
Kevin