SQLCHAR* and const char

Pages: 123... 6
I'm getting this error on this line.... 5 IntelliSense: a value of type "const char *" cannot be used to initialize an entity of type "SQLCHAR *"

SQLCHAR* query = "SELECT COUNT(*) FROM tblIP";

I'm using Access 2010 Direct ODBC with Visual Studio 2010 c++, What can I do to not have this problem. Thank you.
SQLCHAR* query = L"SELECT COUNT(*) FROM tblIP"
const SQLCHAR* query = L"SELECT COUNT(*) FROM tblIP";
How do you use Access 2010 Direct ODBC with VS 2010 c++. That's exactly what I want to do. Can you tell me what I need exactly (besides VS 2010)?
Lamblion. After I get this mess straightened out Ill post the code for you!

Of const SQLCHAR* works but of course further down it breaks. I had this entire thing working but my shared server keeps timing out so for sanity sake I had to ove it to a local Access 2010 database. Here is the next thing giving trouble....

1
2
3
4
5
6
const SQLCHAR* query = "SELECT COUNT(*) FROM tblIP WHERE IP = '%s' AND IPStatus = '1' AND IPType = '3' AND IPMax ='0'";
mysql_query(conn, query);
my_ulonglong i = 0;
res_set = mysql_store_result(conn);
my_ulonglong numrows = mysql_num_rows(res_set);
LEGIT = mysql_fetch_row(res_set);


It's sticking on mysql_query(conn, query);


Lamblion. After I get this mess straightened out Ill post the code for you!


Thank you. I'm looking forward to it. I would help you with your own problem, but I haven't a clue.

IF you prefer, you can email me the code. The email address is -- (strip out ALL capitalized chars)

XXX comments XXX at XXX lamblion.net
Last edited on
Does that code I posted for you not work Lamblion? I tested it with VC9 and GNU Mingw and it works. I don't have VC10 to test it with. I buy Microsoft's latest and greatest every ten years (got ten years out of VC 6 and still using it for COM!), and I just got VC9 Pro two years ago, so I've got eight more years of use to get out of it!
Well, I haven't studied your code yet, and I want MS Access compatibility. Is what you posted the same as what the OP is talking about?

I really do want Access compatibility, so before I go learning something (such as your code), I want to make sure that I'm learning the right thing. IOW, because I want Access compatibility for my current and other apps in the future.

If the code you sent me is the same thing, I'd still like to see what the OP has done.

Also, what is SQL Express or SQL Lite? This is a MS product. Does this product work with VC++, or is it it's own language or interface?
Last edited on
SQLExpress is to SQLServer as Visual C++ Express is to Visual C++. They are the freeware trial versions. The code I posted specifically works with Microsoft Access, although only 1 or two lines need changing to work with (connect to) SQLServer or Microsoft Excel. Getting connected is the hard part. Once you've connected your 90% of the way there.

There are some tricky casting issues involving character string representations involving the ODBC declares. If you look at my code you'll see some strange casting going on. The issues don't arise so much when compiling as C, but seem to crop up in C++ compilation.

You can do a wikipedia search for SQL Lite. That is a completely different database product from SQL Server. Database technology is a real alphabet soup, You have SQL Server, ADO, ADODB, DAO, RDO, MDAC, ODBC, OLE DB, etc.
Okay, thanks. I'll start going though your code. I'd also like to see the OP's code when he's ready.

I downloaded SQLExpress, but I think I'll leave it alone and try to work only with VC++.
freddie1: I get this error when trying to compile --

1
2
1>odbccp32.lib(dllload.obj) : error LNK2019: unresolved external symbol __imp___vsnprintf referenced in function _StringVPrintfWorkerA@20
1>C:\Programming\Win32 Apps\Databases\database_001\Debug\database_001.exe : fatal error LNK1120: 1 unresolved externals


Is there a library that I'm supposed to adding to Additional Dependencies?
This is the contents of my ...

Properties >> Linker >> Command Line...

1
2
3
4
5
6
/OUT:"C:\Code\VStudio\VC++9\MkAccessDB\Release\MkAccessDB.exe" 
/INCREMENTAL:NO /NOLOGO /MANIFEST /MANIFESTFILE:"Release\MkAccessDB.exe.intermediate.manifest" 
/MANIFESTUAC:"level='asInvoker' uiAccess='false'" 
/DEBUG /PDB:"c:\Code\VStudio\VC++9\MkAccessDB\Release\MkAccessDB.pdb" 
/SUBSYSTEM:CONSOLE /OPT:REF /OPT:ICF /LTCG /DYNAMICBASE /NXCOMPAT /MACHINE:X86 
/ERRORREPORT:PROMPT kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib


The last two are the only libs relating specifically to ODBC. Also, I don't think this should make a difference, but I always set up my configuration options to create a stand alone executable, i.e., one not requiring various support files to be present. You are using VC10 I take it?
Do you have odbc32.lib included? I'll have to look up vsnprintf. I'm not familiar with that one. I believe all the printf family of functions are in the CRT.
I named my main source file Main.cpp, and included MySql.h and Sql.cpp. Here is my compile/link output from VC9...

1
2
3
4
5
6
7
8
9
10
11
1
1>Deleting intermediate and output files for project 'MkAccessDB', configuration 'Release|Win32'
1>Compiling...
1>Sql.cpp
1>main.cpp
1>Linking...
1>Generating code
1>Finished generating code
1>Embedding manifest...
1>Build log was saved at "file://c:\Code\VStudio\VC++9\MkAccessDB\Release\BuildLog.htm"
1>MkAccessDB - 0 error(s), 0 warning(s)
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========




For Code::Blocks 10.05 I'm seeing this...



1
2
3
4
5
6
7
8
9
10
11
12

Cleaned "MkAccessDB - Release"

-------------- Build: Release in MkAccessDB ---------------

Compiling: main.cpp
Compiling: Sql.cpp
Linking console executable: MkAccessDB.exe
Output size is 57.50 KB
Process terminated with status 0 (0 minutes, 1 seconds)
0 errors, 0 warnings
Last edited on
I've named the project "database 01"

I don't think that makes a whit of difference. Here is my entire output from a rebuild all. Notice that most of it is warnings, which I can handle. The only error is the one mentioned.

I am using VC++ 2010 Express, /MTd (stand-alone), multi-byte character set, and yes, the odbc libs are included. It says the error in the odbccp32.lib, so perhaps there's a differnece between the 2010 lib and the one you're using.

Here's the output --

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
1
1>  sqlcpp.cpp
1>c:\programming\win32 apps\databases\database_001\database_001\sqlcpp.cpp(64): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\string.h(105) : see declaration of 'strcpy'
1>  main.cpp
1>c:\programming\win32 apps\databases\database_001\database_001\main.cpp(29): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\string.h(105) : see declaration of 'strcpy'
1>c:\programming\win32 apps\databases\database_001\database_001\main.cpp(30): warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\string.h(110) : see declaration of 'strcat'
1>c:\programming\win32 apps\databases\database_001\database_001\main.cpp(61): warning C4996: 'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _stricmp. See online help for details.
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\string.h(246) : see declaration of 'stricmp'
1>c:\programming\win32 apps\databases\database_001\database_001\main.cpp(67): warning C4996: 'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _stricmp. See online help for details.
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\string.h(246) : see declaration of 'stricmp'
1>c:\programming\win32 apps\databases\database_001\database_001\main.cpp(73): warning C4996: 'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _stricmp. See online help for details.
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\string.h(246) : see declaration of 'stricmp'
1>c:\programming\win32 apps\databases\database_001\database_001\main.cpp(88): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(371) : see declaration of 'sprintf'
1>c:\programming\win32 apps\databases\database_001\database_001\main.cpp(89): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(371) : see declaration of 'sprintf'
1>c:\programming\win32 apps\databases\database_001\database_001\main.cpp(90): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(371) : see declaration of 'sprintf'
1>c:\programming\win32 apps\databases\database_001\database_001\main.cpp(91): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\string.h(105) : see declaration of 'strcpy'
1>c:\programming\win32 apps\databases\database_001\database_001\main.cpp(92): warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\string.h(110) : see declaration of 'strcat'
1>c:\programming\win32 apps\databases\database_001\database_001\main.cpp(93): warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\string.h(110) : see declaration of 'strcat'
1>c:\programming\win32 apps\databases\database_001\database_001\main.cpp(94): warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\string.h(110) : see declaration of 'strcat'
1>c:\programming\win32 apps\databases\database_001\database_001\main.cpp(95): warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\string.h(110) : see declaration of 'strcat'
1>c:\programming\win32 apps\databases\database_001\database_001\main.cpp(106): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\string.h(105) : see declaration of 'strcpy'
1>c:\programming\win32 apps\databases\database_001\database_001\main.cpp(133): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\string.h(105) : see declaration of 'strcpy'
1>c:\programming\win32 apps\databases\database_001\database_001\main.cpp(147): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\string.h(105) : see declaration of 'strcpy'
1>c:\programming\win32 apps\databases\database_001\database_001\main.cpp(184): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\string.h(105) : see declaration of 'strcpy'
1>  Generating Code...
1>odbccp32.lib(dllload.obj) : error LNK2019: unresolved external symbol __imp___vsnprintf referenced in function _StringVPrintfWorkerA@20
1>C:\Programming\Win32 Apps\Databases\database_001\Debug\database_001.exe : fatal error LNK1120: 1 unresolved externals
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
Last edited on
Wow! That's a duzzy! I just did a search on odbccp32.lib and came up with the following. Apparently its an unresolved problem with VStudio 2010. I'm still reading about it....

http://connect.microsoft.com/VisualStudio/feedback/details/470376/odbc-application-linking-with-odbccp32-lib-gets-link-errors-in-vs2010-beta-1

I can't make a compile/link fail on any of my systems. I just tried VC6 C++ and that works perfect too.
I'm glad I got 8 more years to go with VS2008. Maybe by then they'll have it fixed! All kidding aside, that's a STOPPER. Unless some of those workarounds work, you're done with ODBC. Me? I'd get another compiler.
Last edited on
I'm amazed you found that stuff.

I got it working with a workaround. I don't think I'll have that problem with a Windows app, so I'm not worried about it, because I NEVER use printf() anymore. And if necessary, I still have VS 2008 installed, so I could always go back to that if necessary.

Anyway, I ran your code (Windows Console App), and all it does is open up a console window showing the path and file name. Is that what it's supposed to do?
No. You've still got a problem then. Like I said before, it first creates an Access Database in whatever directory it is run named TestData.mdb. Then it creates a table in the DB named Table1. Then it writes four records to the table. Then it closes and reopens the table and dumps the four records. If you have VS 2008, why don't you try that? As I said, I can't get it to fail on any of my systems. This should all be visible on your console screen. If all you are getting are those couple lines, something is failing. I could add some debug statements to Main.cpp to see what - likely output the SQLGetDiagRec(). Give me a minute.....
I just ran it on VS 2008 and it compiled fine, albeit I still got the warnings strcpy(), strcat(), etc., but it is still evidently failing because I get the same output.

Just to be clear, I am using multi-byte character set, /MTd (stand-alone debug), and no UAC.

Is that about right?
Pages: 123... 6