简体   繁体   中英

C# App with Existing SQL Server 2008 R2 Database

Am begging to the programming lords, I bit off more than I could chew and need some help. I have tried searching but I don't understand how to apply the solutions to my own.

I have written an application in c# for which I created a database called "Timesheet DB" within Visual Studio 2010 (there is a .mdf file with the application files, and there is a copy in the bin\\debug folder which 'writes if newer' when I debug my app).

I added the tables and views to the "Timesheet Db" Data Connection in the Database Explorer window and dragged them into the designer view of "data_ProjectData.dbml" in my Solution Explorer. My app queries the Data Classes using Linq to Sql.

The "Timsheet DB" is an exact "replica" of a database my business has on our server computer which is using SQL Server 2008 r2 (is this the same as SQL Server Express which I've read about?)

I've been programming this on a computer that is not connected to the network, using dummy figures.

Now I'm stuck.

How do I get my application to read and write from/to the server version of the database instead of the one I have created in Visual Studio on my PC, then deploy it to my server computer?

I want various users on their own PCs connected to the network to be able to read and write to the Db (it is a timesheet application where users submit their times and managers can review and approve), I thought if it would work if they access a ClickOnce application from the server computer (they all have access).

I may make changes to the application from time to time (without the structure of the db ever changing), so I'm worried about not being able to deploy enhancements without messing up their existing data.

My first time delving into SQL server db application - it works beautifully in debug, but if someone can please help me get it working for my business it would be much appreciated!

Cheers Steve

You have to just point the connection string to the server database and it is the only change required.

<add name="ApplicationDB" connectionString="Data Source=serverName\sqlexpress;Initial Catalog=TimeSheetDB;User ID=sa;Password=passw0rd;" providerName="System.Data.SqlClient"/>

This change has to be done in the App.Config for Windows Forms / Console Apps and in the Web.Config for the Web Appliacations.

Please do port the neccessary changes in your machine to the database server. When you have dragged and dropped the necessary tables on to the DBML designer window, this kind of connectionstring will be added to your <connectionStrings> section in the config file.

For ex. if your db is named as TimeSheetDB the connectionstring name will be as TimeSheetDBConnectionString

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