0

I made an application, and there is a problem with deploying a Form with SQL. Actually, somehow I made to deploy, but there is an error with app launching. I installed app on other PC and this is what the part of problem said:

"a database with the same name exists or specified file cannot be opened or it's located on unc share"

.mdf file exists, but dunno whats wrong..

This is my connection string:

SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=Data Source=.;Integrated Security=True;AttachDbFilename=|DataDirectory|\Data.mdf");

and this is app.config:

<connectionStrings>
    <add name="Gym_Software.Properties.Settings.DataConnectionString"
         connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Data.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
         providerName="System.Data.SqlClient" />
</connectionStrings>

Database properties: http://prntscr.com/6ptywq

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

2 Answers2

0

you can use connection string as follow.. Example:-

 SqlConnection con = new SqlConnection("Data Source=TCS3\\SQLEXPRESS;Initial Catalog=551680A3622135F7C7A89A2044CE6B6E_12 2014\\20 12 14\\BACKUP 19 NEW\\19 NEW\\SCHOOLMANAGEMENT\\SCHOOLMANAGEMENT\\APP_DATA\\TCS_SCHOOL.MDF;Persist Security Info=True;User ID=sa;Password=sql2008");

    OR

     SqlConnection con = new SqlConnection("Data Source=TCS3\\SQLEXPRESS;Initial Catalog=Forest_DB;User Integrity Security=True");
0

if the .mdf is a local database than you shouldn't attached it again. drop the attach .... from the string.. it you are deploying and app with a local database than the pc you are installing it should have sql server installed.

ionut spataru
  • 183
  • 3
  • 11
  • I tried but its not working , i need the path to .mdf file, and on second PC .mdf exists, and the path is good, but it cant be loaded.. – Никола Р. Apr 05 '15 at 13:28
  • since it works on your machine with that connection string, then this database it taken from your server, it you install your app on another machine then you should use this connection string : Data Source=190.190.200.100,1433; Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword; remote acces should be allowed on your server and both sql server and windows authentification should be checked. don't use windows authentification on another machine. hope it works. also don't forget to open the port in your firewall . – ionut spataru Apr 05 '15 at 15:13