Basically I have made a MVC3 application that connects to and updates a database that exsists on a server. This database is a test one however, and when I roll out the project live I need it to connect to the actual database. My question is how hard would it be to change the project/application to point at this new database?
I used the database first method, and am aware I would need to change my connection string. I feel it is unlikely to be as simple as that.
Any help, tips or tutorials would be greatly appreciated.
As long as the database structures are the same, it is just as simple as that.
You just need to change the connection string.
Additionaly if you would like to deploy 2 versions of the website, each using it's own connection strings (for example for developpement and production) you can create 2 web.config files. Refer to this link SO question
It shouldn't be that hard. You just need to make sure that the database that you are working on now and the database that you are changing to are equal in table names and column names otherwise you are going to have configure it to use the new database tables and columns.
Related
I have two sql servers installed on my computer (SQL2008 EXPRESS) and also SQL2008 that comes with the specific software that we are using.
I need to make a service that runs all the time and at a specific time updates the non existing records in the SQL2008 EXPRESS from SQL2008.. can you suggest a way of doing this?
Currently the best thing I got is making a local copy in excel file, but that will result 365 excel files per year which I dont think is a good idea :)
p.s. sorry if my english is bad :)
You don't have to hand-craft your own software for that. There are 3rd party tools like OpenDbDiff or RedGate dbdiff to do that. These tools generate the differential sql that you can apply on your target database.
I'm confused when you mention Excel. What would Excel have anything to do with moving data from one SQL database to another?
The short answer is, if you need a C# service, then write a C# service that copies the data directly from one database to the other. The problem that you are trying to solve is not very clear.
Having said all that, and with my limited understanding of the problem, it sounds like what you need is a SQL job that is scheduled to run once a day that copies the data from one server to the other. Since it sounds like they are on separate instances, you'll just need to set up a linked server on either the source or destination database and either push or pull the data into the correct table(s).
EDIT:
Ok, so if a windows service is a requirement, that is perfectly acceptable. But, like I mentioned, you should forget about Excel. You wouldn't want to go from SQL->Excel->SQL if you have no other reason for the data to exist in Excel.
Here is some information on creating a windows service:
Easiest language for creating a Windows service
Here is a simple tutorial on accessing SQL in C#: http://www.codeproject.com/Articles/4416/Beginners-guide-to-accessing-SQL-Server-through-C
If you want a more formal solution (read: data access layer), I'd point you toward Entity Framework. The complexity of the project will probably be the driving factor on whether you just want to do SQL statements in your code vs. going with a full blown DAL.
The problem I'm trying to solve:
I have a dev SQL Server database which is mainly used for staging data entry (occasionally it's getting extra table) and when the person using the system (MVC web app) is happy with the data entry made that doesn't break the system can by single click of a button sync that data with live version of the db on different SQL Server. This avoid getting a developer to do the job every time using RedGate SQL Compare application or similar.
The solution that seems to be the right one is using Sync Framework. I'm trying to create a separate Console App that will connect to the databases and exchange the data but this is where I'm getting lost.
So the first question is: is there any simpler approach?
Second question: if I'll continue with this approach and create provisioning processes in the DB does this means it's one way solution?
Third question: any better tutorials than this http://msdn.microsoft.com/en-us/library/ff928700.aspx because I can't get this to work on two remote servers?
I have searched for ages but only got confused even more.
I'll appreciate every suggestion. Thanks.
Yes, there is a simpler approach. Have all the data in one database. Then add an extra column to your tables indicating the status of the rows. Have the status as "temporary" or "confirmed" or something to that effect. Only "confirmed" rows should be considered the real data.
I've made a local database for a C# project:
I know basic SQL commands, but haven't worked with databases in C#.
What I'd like to know specifically is:
How to read from the database (query)
How to add and update rows
The database only consists of 3 tables, so I don't think anything fancy is needed.
First, you should learn a bit about various technologies and APIs for connecting with a database.
The more traditional method is ADO.NET, which allows you to define connections and execute SQL queries or stored procedures very easily. I recommend digging up a basic tutorial on ADO.NET using Google, which may differ depending on what type of project you're creating (web app, console, WinForms, etc).
Now days, ORMs are becoming increasingly popular. They allow you to define your object model in code (such as every database table would be a class, and columns would be properties on that class) and bind to an existing database. To add a new row to a table, you'd just create an instance of a class and call a "Save" method when you're done.
The .NET framework has LINQ to SQL and the Entity Framework for this sort of pattern, both of which have plenty of tutorials online. An open source project I really like is Castle Active Record, which is built on top of NHibernate. It makes defining ORMs quite easy.
If you have specific questions about any of the above, don't hesitate to post a new question with more specific inquiries. Good luck!
Update:
I thought I'd also put in one last reference as it seems you might be interested in working with local database stores rather than building a client/server app. SQLite allows you to interact with local stores on the file system through SQL code. There's also a .NET binding maintained by the SQLite guys (which would in theory allow you to work with the other platforms I mentioned): http://system.data.sqlite.org/index.html/doc/trunk/www/index.wiki
You can use SQLCE.
This blog will give you a good start.
http://weblogs.asp.net/scottgu/archive/2011/01/11/vs-2010-sp1-and-sql-ce.aspx
Here is a small tutorial that should be helpful to you.
You can make use of the SqlDataReader to read data
and the SqlCommand to Insert Update Delete rows from your tables.
http://www.dotnetperls.com/sqlclient
You could use it by adding following to your Startup.cs
services.AddDbContext<DemoDbContext>(options => options.UseSqlite("Filename=data.db"));
I am doing a school project in C# apps and I decided to create a ticketing system.
I want to impress my teacher (^^) so I decided to add a database for my app.
I have a month to do this so i think I can learn it since I don't have any prior experience with databases.
Could you tell me how to do it? Below is my app, I want to send the info in the TextBox to a database
I already followed the instructions in MSDN which basically tells you how to add a data source in your app. I added northwind dataset to my app, but I don't know what to do with it and how will it be useful with my app...
For a SQL backend, you can use SQLite quite easily. SQLite is simply a file that resides on the local system, so it is totally portable/deployable with your application. It comes with the caveat that the database is not shared between users. It is a single user database. Two people running an application based on SQLite will not share data. For a uni assignment, this is probably not going to be a big deal.
You could also use SQL Server CE (compact edition), which is a stripped down SQL Server implementation which is similar to SQLite (local, embedded, single user). This will allow you to use Visual Studio database tools to design your database.
Once you have a database embedded within your application, you need to design a schema to hold on to this information. If your screenshot is the only data you need to save, a table like the following should do the trick:
TABLE PERSON
COLUMN name varchar(100)
COLUMN address varchar(200)
COLUMN email varchar(100)
COLUMN mobile varchar(15)
You will need to investigate how to create tables in SQL. That should guide you in what you need though. Visual Studio (some versions), also have a database browser/designer.
Then you need to decide how you want to communicate with the database. You have several options.
Linq 2 SQL
Entity
DataTables
Scott Gu has an excellent series on how to use Linq 2 SQL which I would highly recommend reading. It will go the majority of the way to helping you get to where you need.
So now that you have a SQL database and a provider, you can start trying to wire up the database to the form. This is where databinding comes in. You can drag a Data Source onto a form (which is your Person table), and wire up the table to your text fields. There are many examples on the net how to do this.
If you want to take it a step further, look into the ErrorProvider control. It will allow you to bind validation to your data source and text fields. Once again, a few google searches should point you in the right direction.
I haven't provided code samples because this is homework. If you want to impress your teacher, you will do so by truly understanding the technology you're trying to use. These are just pointers in the right direction so you know what it is you can investigate. Best of luck.
That is a pretty broad question, is there something specifically that you need help with? Like connect to the database, use a datareader, etc...?
If you want to impress your teacher, don't refer to MSDN. Use something like couchdb. Don't get caught up in the "prescribed " .net ecosystem.
For software testing purposes I would like to create a sterile clone (with all data blanked out) of the production database. This way I can run my unit tests on a known set of records every time. I am looking to try and do this programmatically within the unit tests themselves so I can ensure that the tables contain exactly the test data that I need for the functional tests.
I have found the following information relating to creating an Access database within C#. Note: I know Access probably isn't the best solution, but its good enough!
What I would like to know, is there a way of using TableAdapters (perhaps) to replicate the production database schema (without any data) within a blank Access database file?
Do this:
create a copy of the access file; production -> test
connect to test database
enumerate all tables in the database
run DELETE * FROM [table] for all tables. run it several times if you have FK dependencies until there is no error - or TRUNCATE [table] as commented
compact the database
I do not have much experience with Access, but generally you would make a CREATE script for this purpose. Most database tools have a function for creating such a script. Such a script basically is a set of SQL statements that create all the objects (e.g. databases, views).
Searching for CREATE script and Access will give you some starting points.
I have bad experiences with Access as a production database. I won't recommend. Either go with SQLite or Firebird.
Secondly, yes you can use TableAdapters. You need to create two connections for each db. But I think there might be tools available to do this.
Edited **
How big is the database? For up to 4GB, Oracle Express Edition might help. Also, it will be easy to clone from Oracle to Oracle.