简体   繁体   中英

C# application deployment with sql server database?

Can anyone tell me the accurate way of deployment my C# application with a SQL Server database? I want to run my application on client's machine, it is running on my machine but showing error on client's machine. I have already installed SQL Server 2012 on client's machine. I know little about deployment as I am doing it for the first time. I know there is a need to attach .mdf file first. Please tell me the exact steps of deployment so that I am able to run my application on client's machine. The thing I need to mention is that the application is simple windows based application!

  1. Click on your Project and add an existing item and browse to your database's .mdf file and select it.
  2. When you successfully added the .mdf in your project you will be able to see it in the solution explorer. Now go back to Properties -> Settings and write “ConString” under the Name column. Select (Connection String) from the Type drop down. Select Application from the Scope drop down. Now in the Value column click to select the Database file. First select Server Name and then Attach a Database file -> Select your .mdf file you just added to your Project. 在此处输入图片说明
  3. You can now use this connection string in your code like this:

     Properties.Settings.Default.ConString; 

    This connection string will be like:

     “Data Source=GAMING;AttachDbFilename=|DataDirectory|\\management_system.mdf;Integrated Security=True” 

    So when you produce the .exe file or setup file of your application your database file will be packaged with it and stored in the |DataDirectory| on your client PC and the connection string will access your database file just like that and your application will work on any PC given that SQL server is installed. I have not found a way to not to install SQL server on client PC and still run the application. If I do find it in the future, I will post it here :P

1 - Attach database to the SQL Server instance (Either using .mdf and .ldf files or using a DB backup)

2 - Change your connection string before deploying the application in client machine. If you don't have a config file and you've hard coded the connection string then you'll have to change the connection string to reflect client's machine name, SQL Instance name and DB name and compile the application before deploying.

You may refer to the following URL to get an idea how to configure your connection string.

http://www.connectionstrings.com/sql-server/

You can probably look at the account used in the connection string.

I suspect that you were using a windows account to access the database on your computer while you haven't added a windows account to the SQL server on the client's computer.

So if you use an SQL user to login to the SQL studio management, you can use this login in your connection string. Or just simply add a default windows account login to SQL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM