Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using Visual studio 2013 to write my web app using MS SQL Server 2012 backend. Below is my connection string which works fine.

C#
<connectionStrings>
  <add
    name="UserDetails"
    connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\UserDetails.mdf;Integrated Security=True;Connection Timeout=30;"
    providerName="System.Data.SqlClient"/>
</connectionStrings>


But while deploying as Web deploy package, I could generate .zip and deploy.cmd and setparameters.xml/SourceManifest.xml file gets generated successfully. As guided in deploy-readme.txt, I executed the below command which was successful.

App.deploy.cmd /T /L -allowUntrusted /M:http://localhost/MSDeployAgentService

I tried to replace /T with /Y and here is where I get the error as below.

Error Code: ERROR_EXCEPTION_WHILE_CREATING_OBJECT
More Information: Failed to create type 'Microsot.SqlServer.Dac.DacServices'. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_EXCEPTION_WHILE_CREATING_OBJECT.
Error: Exception has been thrown by the target of an invocation. ---> System.Exception: The connection string argument AttachDBFilename is not supported

AttachDBFilename was proposed in MSDN. I exactly don't understand the reason for this error.

What I have tried:

I tried not to include the database while publishing and the above command succeeded and I was able to launch the application hosted. However, SQL connection fails at later point. So, I could figure out that I have got some issue with my connection string but I am stuck here for a week. You suggestions will be really helpful and please assist me if I have missed anything.
Posted
Updated 21-Feb-16 4:23am

1 solution

First off, for production you shouldn't be using (localDB) - you shoudl be using the actual name of the SQL server instance that your hosting provider has set up for you.
And secondly, attaching a DB is a bad idea in a web environment - you are much, much better off creating the DB in the SQL server instance and referring to that directly.
See here: Bad habits : Using AttachDBFileName - SQL Sentry[^]
Thirdly, production should never use integrated security - you should configure a user with exactly sufficient rights to do you application task and no more, and use that to connect instead.

For example, my connection string (with some security changes, obviously) is:
HTML
<connectionStrings>
  <add name="MembershipDatabase" connectionString="Data Source=www.palm.MyHostingService.com;Initial Catalog=MyMembershipDatabase;Persist Security Info=True;User ID=SMUserName;Password=SMuserPassword"/>
</connectionStrings>
 
Share this answer
 
Comments
Jones Aaron 22-Feb-16 11:55am    
Thanks. your suggestions and the link shared helped a lot. Removed AttachDBFilename and changed data source as suggested.
OriginalGriff 22-Feb-16 12:15pm    
You're welcome!
Jones Aaron 23-Feb-16 10:57am    
After making changes in Connectionstring to specify userid and password: for eg:

Persist Security Info=True;User ID=admin;Password=1234;

I added a login in MS SQL Server 2014 under Security -> Logins -> with userid & password as admin and 1234. But i am getting the error as below.

Cannot open database "UserDetails" requested by the login. The login failed. Login failed for user 'admin'.

Please help me out. Thanks.
OriginalGriff 23-Feb-16 11:04am    
Check three things:
1) Does the DB "UserDetails" exist in that server instance?
2) Does the user "admin" have permission to access that DB?
3) Is the user password correct? Remember they are case sensitive!

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900