I am trying to create a web application set-up through visual studio set-up project. The database required for the application also being installed within the set-up as a custom action. The user is not providing any user name and password to connect the database. The set-up custom action need to connect database through windows authentication. But when it is tried to connect the database, it is throwing an exception - unable to connect database. Note: the web set-up is being installed with an elevated access. Please provide a solution to connect database through windows authentication from web set-up 'custom action'.
2 Answers
The problem is most likely that custom actions in a VS Everyone install run with system account, not the installing user's account. I bet the DB doesn't allow SYSTEM to do things to it.
They run as system because that's what's needed for them to be elevated. If you look at the docs for the CustomAction table:
http://msdn.microsoft.com/en-us/library/aa368069(v=vs.85).aspx
VS generates ones that have the msidbCustomActionTypeNoImpersonate bit set. Other tools let you say if you want impersonation (of the installing user) or not, but VS does not, so you'd need to use an MSI editor like Orca to edit the CustomAction table after you've identified the right custom action. However it won't run elevated. Longer term, if you need that degree of control, over setups you should look for another setup building tool.

- 20,260
- 1
- 18
- 28
-
I am trying to edit msi with orca. But not able to find msidbcustomactiontype related settings. Under which location I can find msidbcustomactiontype -> impersonate . If it's not there, can I add it as an additional item? – amesh Sep 16 '14 at 20:54
-
Look at the docs for the CustomAction table, http://msdn.microsoft.com/en-us/library/aa368062%28v=vs.85%29.aspx get Orca and edit the MSI file, CustomAction table and the Type contains that bit as in the docs at the link in my answer. – PhilDW Sep 17 '14 at 16:10
-
I had changed the value of type column from 3073(elevated) to 1025(impersonated login user). The msi was able to connect database through windows authentication. But I need to perform few operations within custom action which need admin privileges. I am planning to split the custom actions into two and impersonate one which is creating the database. But I need to perform custom actions one after the other. How can I set the sequence of execution order for custom action in visual studio web set-up? – amesh Sep 17 '14 at 16:29
-
I think the CAs are executed in the order in which you have them in the IDE, the Custom Actions view. – PhilDW Sep 17 '14 at 16:30
-
Then I need to name them in such a way that, they order in the alphabetical order.? – amesh Sep 17 '14 at 16:32
-
I removed custom actions and added in the order what I required. I will test the same and update the status – amesh Sep 17 '14 at 16:36
-
Thanks. Custom actions are executing in the same order how they added in the custom action window – amesh Sep 17 '14 at 17:44
You want to use trusted authentication. This connection string will allow for a silent login to a SQL Server:
Provider=SQLNCLI10;Server=[ServerName OR ServerName\InstanceName];
Database=myDataBase;Trusted_Connection=yes;

- 2,137
- 16
- 14
-
I am already using a connection string with trusted connection= true. Alternatively i tried integrated security =sspi also. Both are not helping on connecting the database. I suspect the privilege of the process which is executing the msi installer. – amesh Sep 16 '14 at 13:10
-
Is the process executing the SQL script a login other than the user running the installer? – Jim V. Sep 16 '14 at 13:21
-
The process installing sql script can install the script with a connection string using user name and password. And the connection string which I am using for windows authentication is working fine if we connect from any normal application. Does the provider which you given with answer -sqlncli10 having any significance? I am using sqlprovider – amesh Sep 16 '14 at 13:24
-
Can you run SQL Profiler to verify which AD login is being used to connect to the SQL Server when run via the installer? – Jim V. Sep 16 '14 at 13:28