Click here to Skip to main content
11,706,323 members (37,971 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: CLR VC++
Do you know where/how in Visual Studio VC++ CLR project a specific Data Connection is referred to/stored? I created VC++ CLR project using SQL Server Project template in Wizard and it made me enter database information while creating it. My project is now completed and I was able to use Deploy functionality of VS for the resulting assembly test SQL server auto-deployment.

I'd like to Deploy to prod server now, and I created another Data Connection in VS Server Explorer for it, but I cannot figure out how to make my project to Deploy to the new Data Connection instead of original one I entered at the creation time. There is nothing in project settings it seems that link the project to specific Data Connections, I looked everywhere...

The only thing I was able to find (by text editor view of file) is the following XML group:

ProjectType="Visual C++"

ManagedDbConnection="01…(very long string with hexadecimal numbers)…A13"

But I am not sure if that’s where Data Connection reference or connection string itself is stored, and in either case it is not something intended to be edited, I would expect Project Properties to have something.

Please help, I already spent over full day trying to figure this out. Spent a lot of time with Google trying to find the answer, but to no avail. I am aware of being able to deploy the assembly/DLL manually, but wanted to use automated deployment if possible. In case it is important, I am working with VS2005.
Posted 14-Jun-12 11:14am
Edited 14-Jun-12 12:03pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I just created a new clr project, and dropped an SqlConnection component on the form. Edited the connection string and void InitializeComponent(void) looks like this:
void InitializeComponent(void)
 this->sqlConnection1 = (gcnew System::Data::SqlClient::SqlConnection());
 // sqlConnection1
 this->sqlConnection1->ConnectionString = 
    L"Data Source=XXXXXX;Initial Catalog=XXXXXX;Integrated Security=True";
 this->sqlConnection1->FireInfoMessageEventOnUserErrors = false;
 // Form1
 this->AutoScaleDimensions = 
     System::Drawing::SizeF(6, 13);
 this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(284, 262);
			this->Name = L"Form1";
			this->Text = L"Form1";
You may not be able to see this because of the code folding in visual studio. If this is the case look for small squares containing a '+' on the left side of the editor.

Best regards
Espen Harlinn
Serbeer at 14-Jun-12 19:40pm
Hm, I do not have anything like it in the code. Perhaps because I use VS2005?
I just created new VC++ CLR SQL Server project, and, as before, it asked me to pick the server to connect to in Add Database Reference dialog. This time it showed both servers I added to Server Explorer, test and prod as options together with button to add a new server.

But after I picked one of the SQL servers and the project was generated, this is mostly empty shell with just

namespace My1 {

public ref class My1Class
[Microsoft::SqlServer::Server::SqlProcedure] static void MyStoredProc();
in main .h file. The only place where there is real content is AssemblyInfo.cpp file. But there is no ConnectionString in it or anywhere in the code. However, when I did binary search through entire directory tree for "ConnectionString", I found it in .ncb and .pch files. Which tells me that it does get compiled in from somewhere at build time. But where is it stored? I am really really confused. I have years of VC++ development experience, but this is my first experience with CLR...
Espen Harlinn at 14-Jun-12 20:00pm
VC++ CLR SQL Server project is for creating stored procedures that executes inside SQL server, so the connection string is implicit.

The code I showed is from a Windows Forms C++ project so it has a connection string.
Serbeer at 15-Jun-12 10:46am
I see. Thanks for trying to help Espen. As I stated in original question, I used SQL Server project template.

That leaves me with the same question: what is the link between specific Data Connection and VC++ CLR SQL Server project and how I can point such project to another Data Connection?
Espen Harlinn at 15-Jun-12 10:51am
Deploy it to the server you want to run it on:

The connection string is usually "context connection=true"

I'm afraid you are mixing the idea of a general .Net C++ application and VC++ CLR Sql Server project.
Serbeer at 15-Jun-12 17:29pm
The link you refer me to says "Select Deploy <project name> from the Build menu" That's what I do now. It then deploys to test server I originally used when creating the project. How can I change it to production server, so that when I select Deploy it deploys to Production server? It does not ask me where to deploy once I "Select Deploy <project name> from the Build menu". It does not give me ability to switch servers in properties of the project. How can I switch the sever to deploy to? It was my original question all along, sigh.
Espen Harlinn at 16-Jun-12 8:41am
This will do the trick:

It doesn't matter that your assembly is written in C++, look at "Deploying the Assembly to Production Servers."

For some reason, which totally escapes me at the moment, I got it into my head that you where mixing/confused about regular .Net applications vs VC++ CLR SQL - sorry about that ...
Serbeer at 18-Jun-12 15:34pm
Thank you very much Espen for helping. I guess the answer is that there is no way to switch to another server. The only way to deploy to another server is to use Management Studio to auto-generate assembly deployment script from the original test box. Strange but true I guess. Thank you again for all the help.
Abhinav S at 15-Jun-12 2:37am
Espen Harlinn at 15-Jun-12 2:51am
Thank you, Abhinav!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 197
1 Sergey Alexandrovich Kryukov 141
2 chainerlt 110
3 Mika Wendelius 80
4 ppolymorphe 71
0 OriginalGriff 9,070
1 Sergey Alexandrovich Kryukov 8,413
2 CPallini 5,189
3 Maciej Los 4,746
4 Mika Wendelius 3,676

Advertise | Privacy | Mobile
Web01 | 2.8.150819.1 | Last Updated 14 Jun 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100