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
Related
I'm pretty new to developing in Visual studio and working on databases.
I am working on a program that deals with reading and writing data to a database that I created with Visual studio.
I need to work on this project from another computer and copying over the project files was a breeze but I'm facing issues when it came to copying the .mdf database file.
Upon research it seems like, at least in the Microsoft SQL Server program, that I would have to "Detach" the database before copying it over to a different computer. So I am assuming I would have to do something similar with my Visual Studio Database as well.
Anyone has any inputs with regards to this?
If there is not much that I can do, I guess I could recreate all my tables and everything in Microsoft SQL Server program, so that it would be easier to move the database if needed.
I was in a similar situation such as yourself when I began developing my first core application. You have a few different options including:
Detach an already created database from the hosted SQL Server service and "re-attach" to another SQL Server service that is accessible from the desired set of hosts. You have to essentially disconnect the database from the service before you are able to transfer or migrate it since the process will have an exclusive lock on the .mdf file. https://msdn.microsoft.com/en-us/library/ms190794.aspx
Create the necessary .sql scripts to construct the database and run in the appropriate order e.g. create database, create tables, etc. to re-construct the database at the service location.The neat thing about this technique is if you have already created the database (which it sounds like you have) SQL Server allows you to generate scripts rather than having to write them yourself. https://technet.microsoft.com/en-us/library/ms178078(v=sql.105).aspx
Finally you may use a subscription based service such as SQL Server through Azure to host the service for controlled global access aka DBaaS (Database as a Service). I can't post anymore links, but look at Microsoft's Azure SQL Server hosting service if you are curious about this option.
The unfortunate part you have to decide is how much time you would like to invest in this. I began developing the application from scratch which led me to developing scripts to conjure up the database for deployment purposes. Good luck!
I have made a Wpf application and i am using linq to SQL classes also i have made my database in SQL server 2012 so is there any way that i can deploy my application in such a way that it will run on other PC's?
Check your app.config file. Make sure your connection string contains:
valid DataBase address
Valid credential for the db
As your update:
whenever i make setup file and run on another pc it give me exception
because sql server isnt installed on that pc
Either you need to deploy a database in internet, accessable by your app. Or you have to use an embedded sql db (e.g. add a db.mdf to your solution). I think this suit you better.
here is the problem I am facing now. I have created an application that uses local database (this was created by Add -> New Item -> Local Database. Afterwards I have added tables under this .sdf database.
Then I have connected to this database using Add -> New Item -> ADO.NET Entity Data Model.
Everything works like a charm, unless I was asked to move this database to a place, where multiple people could access this database and work with it.
Therefore, as I have no previous experience with databases, I have treated this .sdf file as any other file (let's say Excel workbook) and I thought that I could simply take already existing database, copy it on server computer (e.g. \Server001\Database\Database1.sdf) and simply change connection string under app.config.
However the problem is that this does not work. As I didn't know how to change connection string, I created new application, where I have tried to connect to this database located on a server computer; however I received the following error:
SQL Server Compact does not support opening database files on a network share.
I already have fully functioning program, but I have no idea how to make it work with multiple users. I have tied to google for solution, but all I could find is how to create local database, not how to make it accessible by placing it in server computer.
Could you guys please help me? If you need more details, please let me know!
P.S. This is WPF application, .NET 4.5, created using Visual Studio 2012 Professional.
Thank you!
The error message pretty much sums up the problem: SQL Server Compact does not support opening database files on a network share.
SQL Server Compact (aka "local database") is to be consumed by a local application; even if it was a web app serving many requests, the application itself is local.
If you want to have multiple remote connections (i.e. centralized DB, distributed app), you should look at using an instance of SQL Server (any SKU would probably work, even SQL Server Express). Those will use MDF files instead of SDF files, so you might want to refer to Convert .sdf database to .mdf database. You'll probably also need to set up a user identity for your connection string, so check out this link on CREATE USER and Difference between a User and a Login in SQL Server to understand how that can be configured.
I am developing C# windows application first time.
Que 1 - ) I have developed my windows application which uses SQL server 2008 using below connection string..
Data Source=myMachineName;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
But When I created setup of my application and installed it to another computer then it is throwing error of could not establish connection with SQL server..
I guess this error is because of my connection string as it is specific to my computer and installing it to another computer will not work..
Hence How can I make my connection string which will work with any computer..
Que 2 - Do I need to attach schema file with my setup as How my database will be created into the other computers??
This might be silly qustion but as I am doing this first time , i dont know about this all.
Regards,
Mahesh
You should place your web config in app.config file which is in xml format.
And read it from your code.You can easily change app.config file through notepad according to machine.
Yes must have your schema script in setup if you want to create it from setup.Otherwise you create database manual on client machine.
If you've used SQL Server on your development machine, it has to be installed on every computer that will be using your app. There are several options to resolve this issue:
If your app doesn't need access to a central sql server (for example your app just keeps track of users DVDs), use SQL Server Compact Edition instead and embed it to your app
If your app needs some kind of a centralized data, get a dedicated SQL server first, install there everything you need and in your app change your current myServerAddress to the address of the server. Note that the server needs to be accessible from remote locations (some restrict access to localhost!).
Que 2 - Do I need to attach schema file with my setup as How my
database will be created into the other computers??
Again, multiple options. For instance, you can export your database to a .sql file (Right click on the db in your DB explorer and select option Publish to provider) and then import it using a sql manager on other computers. Or maybe you can create a .cs installation script, that will do the same job using C# code.
Edit based on OP's comments:
Example links for solutions:
question1: Embedding SQLServer CE in an installer
question2: http://support.microsoft.com/kb/307283
Okay that's fine but will my current Connection string work in that case as the DataSource
is my specific machine name
Of course not, you'd have to change it to point to the SQL Server CE database file. Probably the best way is to not hardcode it, but use a relative path to the database. It looks like this for instance:
Data Source=|DataDirectory|\MyDb.sdf, where |DataDirectory| points to the App_Data folder of your application.
Also plese see the error screen map i have attach with the question..
Your error is quite clear - there was a problem establishing a connection to your database. It either doesn't exist or isn't accessible from your current machine.
Currently my website is written in ASP.NET Webforms using a SQL Server database. I am planning to build a ASP.NET MVC application not because it's better but because I want to learn the technology. My question is more specific to the database. I can create the database and import my SQL table via the import feature of the web interface to the SQL database or I can use a "local" database MDF file. I like the idea of using a MDF file because it will be easier to backup and deal with. My website doesn't get a lot of traffic... matter of fact I could be the only user. :) Now here is the question.
How much of a performance hit will I get by using a local SQL Server MDF file instead for my database?
Effectively none. Or really none more than having the DB run on the same box as the web site. It is still a Sql Server Express database all the same. Production-wise, you probably want the DB running on a separate box dedicated to serving databases. But code-wise, the only difference will be your connection string.
SQL Server uses a MDF file for each database on its server. There is no difference between a MDF file and a 'database' because the 'database' gets stored in a MDF file anyway.
Performance wise you should not see a difference.
The biggest issue is with production deployment and management. It is MUCH easier to manage a standard database, than a dynamically attached .mdf.
Also, don't forget that your web host has to support this as well. And since SQL Server Express is the only SKU that supports "user instance" databases, the host will have to have Express installed for you to use it as-is. OTOH, you can develop with it this way and then just deploy your database and change the connection string when you deploy to the web host.
The only difference beyond the normal resource limits of the Express version of SQL Server is a negligable startup cost while the SQL Express engine connects to the MDF file, does its routine checks for file integrity and transaction log stuff.
This should only happen on application start up, not for every request.