Emad
Emad

Reputation: 73

How to deploy and attach SQL Server Management Studio 2012 Database with Winform Application?

I am using Visual Studio 2012 with SQL Server Management Studio 2012, At very first I created a database named salesystem in SQL Server Management Studio 2012, I created views and tables also in SQL Server Management Studio 2012 ... Then

  1. I created a new Winform Project,

  2. Then I created a new Data connection in Server Explorer (Visually > Not by Coding) in Visual Studio 2012. Server Explorer > Add Connection > (In Server Name I gave . and selected my database from the combo box given there , I clicked TEST CONNECTION (It gave me Connection Successful !) then I clicked OK ).

  3. Then I created a NEW DATA SET by clicking on Solution Explorer > Add > New Item > Dataset.

  4. Then In Data Set I Dragged Tables from my Database. And started working with my Database.

Now the problem is that when i wish to publish my project, my database is not attached with it! What to Do Now???

  1. How can I publish this Application with my Database created in SQL Server Management Studio 2012??

  2. How can i reference my Database to my Winform Application?

  3. Do i have to reference it before publishing? If YES, then HOW????

  4. IF ... someone in one of you helped and solved my problem, then when I install this Application with database on my client PC, and install SQL Server 2008 Express OR SQL Server Management Studio 2012, will I have to give server name. In his PC?? After installing and running SQL Server Management Studio 2012???? If yes then, how can I configure database reference settings after my application is published?

I know this is a very long question but I am stuck very badly!!! Any Help Will Be Appreciated....

NOTE : I don't know any other method on how to make a database app in winforms in visual studio 2012 , so please try to help me in my way , Not by telling me to use SQL Compact or LOCAL Database in my app !!! I know it’s a tricky question!

Upvotes: 0

Views: 4291

Answers (2)

user2509901
user2509901

Reputation:

When you deploy you have to attach the file to the Applications Folder. I dont think you can do this with publish wizard so I'll advise you use

They have facilities to attach your database to the Applications Folder of your user.

Upvotes: 2

Eiaddar
Eiaddar

Reputation: 180

Actually your problem in your connection string
try this:

1- add a copy of your database to your debug file.(you can fine your database in

"C:\Program Files\Microsoft SQL Server[your instance name]\MSSQL\DATA[your database Name]")

2- modify your connection string (in app config )

Server=.\SQLExpress;AttachDbFilename=|DataDirectory|YourDB.mdf;
Database=YourDBname;Trusted_Connection=Yes;

3-try to deploy.

Note: the database version must be equal or lower of server instance version and this is manual way the better way but the better way to attache database to sql server in deployed PC

Upvotes: 0

Related Questions