GIDForums  

Go Back   GIDForums > Computer Programming Forums > .NET Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 24-Aug-2004, 11:42
wfillis wfillis is offline
New Member
 
Join Date: Aug 2004
Posts: 6
wfillis is on a distinguished road

Help! undeclared identifier error


Hello. I am a newbie to VC++.Net, having a total of 4 days experience... I have a VB6 and SQL Server background.

I am trying to create an instance of SqlXmlCommand, but get a compile error 'undeclared identifier'. I have added the 'Microsoft.Data.SqlXml' dll to my references, and use the following code:

TCHAR szConnectionString[500];

_tcscat(szConnectionString, "Provider=SQLOLEDB;Data Source=");
_tcscat(szConnectionString, szServer);
_tcscat(szConnectionString, "\\NetSDK");
_tcscat(szConnectionString, ";Initial Catalog=");
_tcscat(szConnectionString, szDatabase);
_tcscat(szConnectionString, ";Trusted_Connection=yes;");

SqlXmlCommand* spCMD = new SqlXmlCommand(szConnectionString));

When I type 'Microsoft.Data.SqlXml::' I get SqlXmlCommand listed, but when using '::', I get this error:

": error C2882: 'Microsoft' : illegal use of namespace identifier in expression"


I know I am missing something really stupid, but all the documentation and sample code for SqlXmlCommand is in C# and VB.

I am using a SQL Server extended stored procedure project. I intend to call the extended stored procedure from SQL Server, passing the name of a XML Template with embedded SQL. The DLL will use SqlXmlCommand to prepare a XML document which I'll save as a XML file.

If you can help, I'd be very grateful!
  #2  
Old 25-Aug-2004, 02:10
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 890
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough
The answer it is what it is probably seems stupid
http://msdn.microsoft.com/library/de...err28xx_58.asp

Quote:
Originally Posted by wfillis
When I type 'Microsoft.Data.SqlXml::' I get SqlXmlCommand listed, but when using '::', I get this error:

": error C2882: 'Microsoft' : illegal use of namespace identifier in expression"

What do you mean by using "::"? Please show the code where you use this...

If I missunderstood the question, sorry...

Regards,
Luci
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #3  
Old 25-Aug-2004, 02:30
wfillis wfillis is offline
New Member
 
Join Date: Aug 2004
Posts: 6
wfillis is on a distinguished road

::


Thanks for the prompt reply!

I use:

Microsoft.Data.SqlXml::SqlXmlCommand* spCMD = new Microsoft.Data.SqlXml::SqlXmlCommand(szConnectionS tring));

and get these compile errors:

error C2882: 'Microsoft' : illegal use of namespace identifier in expression
error C2228: left of '.Data' must have class/struct/union type
error C2653: 'SqlXml' : is not a class or namespace name
error C2228: left of '.SqlXmlCommand' must have class/struct/union type
  #4  
Old 25-Aug-2004, 03:02
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 890
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough
Quote:
Originally Posted by wfillis
Thanks for the prompt reply!

I use:

Microsoft.Data.SqlXml::SqlXmlCommand* spCMD = new Microsoft.Data.SqlXml::SqlXmlCommand(szConnectionS tring));

and get these compile errors:

error C2882: 'Microsoft' : illegal use of namespace identifier in expression
error C2228: left of '.Data' must have class/struct/union type
error C2653: 'SqlXml' : is not a class or namespace name
error C2228: left of '.SqlXmlCommand' must have class/struct/union type

Hmm, I think you might have a problem with the TCHAR...
I suppose since you use managed extensions, it expects you to only have data on the managed heap. I'm not sure though...
Try using something like:

CPP / C++ / C Code:
System::String __gc* szConnectionString;

Hope this is right, I don't have .NET at work. This will ensure using managed strings; please let me know if it solves your problem.

Regards,
Luci
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #5  
Old 25-Aug-2004, 03:24
wfillis wfillis is offline
New Member
 
Join Date: Aug 2004
Posts: 6
wfillis is on a distinguished road

error on _tcscat


I now get an error on:

_tcscat(szConnectionString, "Provider=SQLOLEDB;Data Source=");
_tcscat(szConnectionString, szServer);
_tcscat(szConnectionString, "\\NetSDK");
_tcscat(szConnectionString, ";Initial Catalog=");
_tcscat(szConnectionString, szDatabase);
_tcscat(szConnectionString, ";Trusted_Connection=yes;");

Could you suggest replacement code now what szConnectionString is a string not TCHAR?

Wayne
  #6  
Old 25-Aug-2004, 04:18
wfillis wfillis is offline
New Member
 
Join Date: Aug 2004
Posts: 6
wfillis is on a distinguished road
Am using String::Concat in place of _tcscat.

Still get the same 'undeclared identifier' compile error, though...
  #7  
Old 25-Aug-2004, 04:25
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 890
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough
Quote:
Originally Posted by wfillis
I now get an error on:

_tcscat(szConnectionString, "Provider=SQLOLEDB;Data Source=");
_tcscat(szConnectionString, szServer);
_tcscat(szConnectionString, "\\NetSDK");
_tcscat(szConnectionString, ";Initial Catalog=");
_tcscat(szConnectionString, szDatabase);
_tcscat(szConnectionString, ";Trusted_Connection=yes;");

Could you suggest replacement code now what szConnectionString is a string not TCHAR?

Wayne

Oh, of course you can't use the same code...
Like I said, I don't have .NET on my computer, but it probably is something like:
CPP / C++ / C Code:
szConnectionString = "Provider=SQLOLEDB;Data Source=" + szServer + "...";

Although I'm not sure about concatanation between strings in .NET - you might get something about adding 2 pointers - it works in Java.
In case this doesn't work, try doing it at allocation (new(stuff I wrote)).

Anyway, once you manage the concat, it should work....
Ohh, what about String::Copy? You might want to give that a try too.

Sorry, I don't even have VS 6 right now - just try a little variation on these things, I'm sure you can manage.

Regards,
Luci
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #8  
Old 25-Aug-2004, 05:55
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 890
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough
Quote:
Originally Posted by wfillis
Am using String::Concat in place of _tcscat.

Still get the same 'undeclared identifier' compile error, though...

I didn't see this reply... I'm pretty sure the site has some problems with the refresh. It might be my connection though....

Quote:
Originally Posted by wfillis
'undeclared identifier' compile error
Do you mean "illegal use of namespace identifier "?

If so....do you get the other errors as well?
Try including the namespace Microsoft.Data.SqlXml and then just use SqlXmlCommand by itself.
Also, make sure your project has "Managed Extensions" enabled. Don't ask me where you check this, like I said
Quote:
Originally Posted by LuciWiz
I don't have .NET at work

Sorry.
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #9  
Old 25-Aug-2004, 06:03
wfillis wfillis is offline
New Member
 
Join Date: Aug 2004
Posts: 6
wfillis is on a distinguished road

Works


Thanks!!!!

Used:

CPP / C++ / C Code:
#using <c:\Program Files\SQLXML 3.0\bin\Microsoft.Data.SqlXml.dll>

using namespace Microsoft::Data::SqlXml;

SqlXmlCommand* spCMD = new SqlXmlCommand(szConnectionString);

The main source of the problem was that VC++ didn't like the full stops in Microsoft.Data.SqlXml, it wanted :: in place of the full stops!

Thanks for the help! Now I must just see how I can convert my TCHAR variables to the strings you suggested I need to use.
Last edited by LuciWiz : 06-Feb-2006 at 07:24. Reason: Please insert your C++ code between [c++] & [/c++] tags
 
 

Recent GIDBlogToyota - 2008 August Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Operator Overloading: << aaroncohn C++ Forum 36 07-Dec-2004 19:22
Including Maps and strings?? maddie C++ Forum 17 05-Jul-2004 06:25
link error? pablowablo C++ Forum 14 19-Jun-2004 10:00
OpenGL always reports error mvt OpenGL Programming 2 04-Jun-2004 06:42
some I/O problems...again cameron C++ Forum 3 03-Mar-2004 21:39

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:17.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.