0

I have written a C# program in Visual Studio 2010. I use database for my program by add service-based Database in VS2010. I make setup by add setup item for program. In my computer the program installed successfully and run very good. but in another machine after installing program when I want to work with database of program, 1 exception happened:"the program can't find sql....." and some errors like this.

Connection string is: (in single line)

"Data Source =.\\SQLEXPRESS;
 AttachDbFilename=|DataDirectory|\\database.mdf;
 Integrated Security=True;
 User Instance=True"

Also I included database.mdf file into setup files, but this problem has not been sloven. what's my connection string must be? Is this exception for that string?

Mat
  • 202,337
  • 40
  • 393
  • 406
irisadaf
  • 101
  • 3
  • 12
  • ok. 1) please post the full exception. 2) the location on the server of the database.mdf – Preet Sangha Aug 13 '11 at 12:40
  • "Could not open new database'c:/programfiles/program/database.mdf' create database is aborted. an attempt to attach an auto-named database for file 'c:/programfiles/program/database.mdf' failed. A database with the same name is exist,or specified can not be opened or it is located on UNC share. – irisadaf Aug 13 '11 at 12:56
  • But I didn't had database.mdf before installing program! – irisadaf Aug 13 '11 at 12:58
  • Have you includef idf file in addition to mdf. And are they installed at location exception shows? – elevener Aug 13 '11 at 13:03
  • In continue of this expetion:" the activition failure. the physical file 'c:/programfiles/program/database.ldf' may be incorrect. – irisadaf Aug 13 '11 at 13:06
  • The problem solved when I include 'database_log.ldf' file into setup. Thanks elevener. But Is any way to runnig this program in another machine without installing sql server,because this had large size . My program sized about 2 Mb and need sql server about 100 Mb! . If I use another database like mysql ,is necessary to install it too?! – irisadaf Aug 13 '11 at 13:25
  • Some database have embedded versions that dosen't require installation - for example MYSQL, FireBird or mentioned below SQLite. You can try to use one of them – elevener Aug 13 '11 at 15:54
  • "Some database have embedded versions that dosen't require installation - for example MYSQL, FireBird or mentioned below SQLite. You can try to use one of them" ..How? can you explain more? – irisadaf Aug 14 '11 at 11:02
  • Had a check. With MySQL where would be problems, their current version of connector doesn't supports embedded version. With FireBird here is a link (look a question and answer) that describe usage http://stackoverflow.com/questions/4014097/how-to-connect-and-use-firebird-db-embedded-server-with-visual-c-2010. With SQLite I never worked so better ask someone else. Have a look also at MS SQL Compact edition microsoft.com/sqlserver/en/us/editions/compact.aspx| but it's not free – elevener Aug 14 '11 at 18:49

1 Answers1

0

The data source \SQLEXPRESS shows me that you're using a SQL Server Express Edition installed to your machine. When you distribute the program along with the database file, the SQL Server Express Edition must be installed on the target machine. Try using an embedded database like SQLlite if this is not desired, otherwise include SQL Server Express Edition within your installer.

Matten
  • 17,365
  • 2
  • 42
  • 64
  • can you please give us the full exception? "the program can't find sql..." is a little unspecific :) – Matten Aug 13 '11 at 12:51
  • when I installed sql server on that machine the exception was : – irisadaf Aug 13 '11 at 13:01
  • "Could not open new database'c:/programfiles/program/database.mdf' create database is aborted. an attempt to attach an auto-named database for file 'c:/programfiles/program/database.mdf' failed. A database with the same name is exist,or specified can not be opened or it is located on UNC share – irisadaf Aug 13 '11 at 13:02
  • ^seems like the exception _message_, not the complete exception – Jake Berger Aug 15 '11 at 21:42