0

I have developed an application on VS 2012 using SQL Server 2012.
My database is in .mdf file in other drive and working on my system. Now my question is I want to deploy my application to my client, so do I need to install whole SQL Server on my client system or not?

I am using this connection string:

mycon = New SqlConnection("Data Source=.;Initial Catalog=G:\RjAccount\Database\
                                                 Rj.mdf;Integrated Security=True;")
Sheridan
  • 68,826
  • 24
  • 143
  • 183
user3284202
  • 1
  • 1
  • 1
  • [LocalDB is the answer](http://stackoverflow.com/questions/9655362/localdb-deployment-on-client-pc) – Steve Feb 07 '14 at 14:55

1 Answers1

0

You can copy the database file Rj.mdf to your Bin\Debug folder (application path) and then use your SQLCONNECTION like this:

mycon = New SqlConnection("Data Source=.;Initial Catalog=" & Application.StartupPath  & "\
                                             Rj.mdf;Integrated Security=True;")

or if you use WPF you change your code like :

Public Conn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=" & System.AppDomain.CurrentDomain.BaseDirectory & "Rj.MDF;Integrated Security=True;Connect Timeout=30;User Instance=True")

But please remember that you need to use "\" after app path in winforms but in WPF you don't need to use it. let me know if it helped you :)

Eldar Zeynalov
  • 379
  • 5
  • 19
  • mycon = New SqlConnection("Data Source=.;Initial Catalog=G:\RjAccount\Database\ Rj.mdf;Integrated Security=True;") – user3284202 Feb 08 '14 at 10:11