Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I created a windows application and i created database for that application in sql server 2005.then i add connection to the database from server explorer(right click on Data connections-->add new connection)every thing works fine in my system.when i create the setup file by creating the new setup template or by clicking on publish.the files .msi or .exe wont work on other computers because the database is not included in the project.
how to include the databe in the executable file(not sql server express simply database only)
Posted

Hi,

You could use custom actions in your visual studio installer project to install your database on the target computer.

A good start would be to read this very good article that will explain you how to do it.

Deploy SQL Server databases easily with an Installer class[^]

You can also consult msdn for detailed information.

Valery.
 
Share this answer
 
Hope this[^]will give you an idea.
 
Share this answer
 
Comments
krishna_goluguri 8-Jan-11 3:09am    
through the links its not worked please give me step by step description by taking a small example please
Also, have a look at these discussion links:
Link 1[^]
Link 2[^]
Link 3[^]
 
Share this answer
 
Comments
krishna_goluguri 8-Jan-11 3:09am    
through the links its not worked please give me step by step description by taking a small example please
you should copy file database with file .exe and install sqlserver2005
and use this code in load form
string mypath = string.Empty;

mypath = Application.StartupPath.ToString();
SqlConnection attachCon = new SqlConnection("server =(local);database=master;Integrated Security=True");

SqlCommand cm = new SqlCommand();
cm.CommandType = CommandType.Text;
cm.CommandText = "sp_attach_db @dbname = N'Metal', " +
" @filename1 = N'" + mypath + "\\DB\\Test_Data.MDF" + "'," +
"@filename2 = N'" + mypath + "\\DB\\Test_Log.LDF" + "'";
attachCon.Open();
cm.Connection = attachCon;
cm.ExecuteNonQuery();
 
Share this answer
 

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