Click here to Skip to main content
15,922,325 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have develpoed application in winforms ,but when i open n client machine there are error occured
" failed to generate a user instance of sql server due to failure in copying database files.the connection will be closed"
please give me solution for this

What I have tried:

ConnectionString = "Data Source=mypc\SQLEXPRESS;
AttachDbFilename=mydb.mdf;
Integrated Security=True;

User Instance=True";
Posted
Updated 30-Nov-17 22:22pm
Comments
Richard MacCutchan 1-Dec-17 3:39am    
Check the connection string and location of all files.

1 solution

Start by not attaching the database: that is a special mode which is only available in Express editions and is intended as a development aid. If you want to share the DB between multiple clients, you cannot attach it - it must be hosted and maintained by SQL server directly.

So create a new database in SQL and populate it with data from your file, and then modify your connection string to connect to it.
 
Share this answer
 
Comments
Member 13275563 1-Dec-17 4:30am    
Yes ,I have created new database with data in sql server,and modified connection string,but still same error occured,what should i do now
OriginalGriff 1-Dec-17 4:54am    
So what does your new connection string look like?
Member 13275563 1-Dec-17 9:09am    
YES So my app connectionstring look like this

<?xml version="1.0"?>
<configuration>

<connectionstrings>
<add name="LN.Properties.Settings.dbLnConnectionString"
connectionString="Data Source=myPC;Initial Catalog=dbLn;User ID=sa;Password=sa123;User Instance=True"
providerName="System.Data.SqlClient" />



<system.windows.forms jitDebugging="true" />

<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>

But still this error occured,plz give me solution.i have face this problem since 15days
OriginalGriff 1-Dec-17 9:40am    
That string doesn't look right:
"Data Source=myPC" is unlikely - you'd normally have an SQL instance name on that as well.
"Provider=..." is not a keyword SQL Server supports.

Have a look here:
https://www.codeproject.com/Tips/1198443/Simple-SQL-Connection-String-Creation
It should help you (and your client) generate a working connection.

BTW: The sa user is not recommended - you should create a user with just enough permission to to the app's job. "sa" has full access to all DB's and can do anything to the system. Using that exposes your admin login to casual users, and puts things move at risk if there is an error in your code.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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