I am new to this forum, so, I hope this is the right place to post this issue.
I am an experienced programmer, but I am starting to develop modern VC++ applications. Nowadays, I am programming mostly in C# 5.0.
In an effort to learn modern C++, I have converted several small utilities, I normally use, from C# 5.0 to C++, using MFC. The new versions open faster, perform much better, and have a very small footprint. STL is impressive. Unfortunately, the user interface is much poorer when compared to the DevExpress suite I use for C#. I hope there are similar suites for C++ too. Are any of you aware of one I could try?
Alas, I am unable to find any simple MFC C++ sample showing how to execute an SQL Server 2012 Store Procedure that takes parameters and returns one or more recordsets.
I have been browsing the Web for days. All the samples I found are very old (VC++ 6.0), most do not even compile, some are ATL related, and other are VC++.Net related.
I will not be able to do any serious work without easily accessing SQL Servers.
Would any of you please kindly point me to any resource (sample, book, e-book, documentation, etc.) that could help me perform this very simple task? Microsoft's own documentation does not have many samples, and not one specifically illustrating how to do this simple operation.
I am under the impression that Microsoft is deprecating MFC. Is this true? Besides the modern interface, which does not apply in my case because my clients mostly run Windows 7, what is the preferred way to develop native C++ Windows line-of-business applications?
Thanks very much for any suggestion.
Google "t-sql c++" returned many possible solutions. It looks like you first have to pick how you want to talk to the server.
Re: the "how do I write UI in a native C++ app" question:
I would normally suggest writing a Windows Store app, but there is a requirement that the app run on Windows 7.
I believe MFC is still supported, but more recent UI frameworks (that still run on Windows 7) would include Windows Presentation Foundation and XAML.
Here's an example of how to call a stored procedure using the native C++ OLE DB APIs:
As for WPF, as far as I know, and according to this Microsoft site Introducing Windows Presentation Foundation, WPF is a .NET technology. I know by fact that Visual Studio is written in WPF and C++, but this king of integration is not easy, so much so, that the next VS version will be entirely developed in .NET (albeit, compiled with a new technology that generates native code from C# and VB.Net).
XAML seems interesting. I will try to learn it. But it will be something else to master in.
As for the C++ OLE DB APIs, thanks for the hint. I am already reviewing the code, but It seems too complex for a simple task:
Connect to an SQL Server,
Execute a stored procedures with two parameters and
Read the resulting recordset.
I had seen it before, but I deemed it too much code for such a simple task. Is there a simpler way of doing it?
I tried and ran the samples using OLE DB. The problem is that the SQL OLEDB Client is deprecated by Microsoft, so much so, that I had to define the following constant to have the sample program compiled:
#define_SQLNCLI_OLEDB_IGNORE_DEPRECATION_WARNING_ Is there another way of accessing an SQL Server that is not depreacated by Microsoft?
I didn't realise it had all moved on. Apparently Native Client is now where it's at.
"SQLOLEDB: The Microsoft OLE DB Provider for SQL Server (SQLOLEDB), which supports access to Microsoft SQL Server, has been deprecated. Its connectivity to future versions of SQL Server may not be supported. The ability to connect to versions earlier than SQL Server 7 will be removed from the operating system after Windows 7. New applications should use the SQL Server Native Client OLEDB provider, which supports new SQL Server features."
"After SQL Server 2012, the SQL Server Native Client OLE DB provider will no longer be included in SQL Server Native Client."
The SQL Server Native Client ODBC provider is a C programming-language interface, not a C++, much less a modern C++ one, but it is manageable. In my case, as soon as I grab its workings, I will create a class to deal with all my store procedures and isolate myself from C style programming complexity.
I found some samples in the Microsoft documentation. I am trying to make them compile and run in my development environment. Alas, I am having a linking errors:
Error 1 error LNK2019: unresolved external symbol _GetUserNameExW@12 referenced in function _main c:\Users\Eduardo\documents\visual studio 2013\Projects\SqlNativeClient\SqlNativeClient\SqlNativeClient.obj SqlNativeClient.
I will somehow figure how to solve this problem and finish my testing.
I just had to add ;Secur32.lib to the end of the project's properties->Debug->Linker->Input->Additional Dependencies line.
It compiled and worked perfectly. Now I will try other samples.
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.