i am quite new in programming, and have few questions regarding in play with the database...
(sorry if i make my post bit long)
I learn to work with Visual Studio 2008 using C#
1. How to create the database? - is there a correct way for always?
How i learned to do it:
- In the Solution Explorer i right click and then go to Add -> New Item... -> (select) Service-based Database -> (click) Add -> Finish. and that is all. Then in Solution Explorer i go in app.config and from there i can find the connection string that later on i can use it, and it looks like this:
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True"
So is this the correct way to create a database? Later on as i tested, i would need to install SQL Express to the computer that doesnt have visual studio in order this database could work for the program..
So is there better ways in creating a database, or this is just fine..
2. How to secure the database from others to open it?
With this i mean, someone else in visual studio might also open the tables and records and everything that is in the database. Simpy by just creating a new project, right clicking on "Server Explorer" window then "Add connection" as a data source to choose "Microsoft SQL Server Database File" then simply to browse the existing database. And after that, you have full access on the database. So any tips about this?
3. How to create a database programmatically?
So my idea here is that in the future i might want to create a new database that a program would use (that already is connected to another database). But have no idea on how i would use that connection string (how to get it), if the database is made using code (a button is clicked by the client for example to create a new database for a new "working year"). I have tried few from the examples i found on the internet for creating a database, but it always trows me an error...
I know that this questions are not specific, but i am new in programming and am bit unsure if i am doing the right way, and i know this place isn't like a forum, but i thought i might get some good answer that would guide me towards building my future knowledge...
P.S. I am quite young, and sorry if i made some mistakes in the writing (english is not my main language)...
(and if i was not clear in some way, please tell me and i ll try to be more clear)
How to create the database? - is there a correct way for always?
For, small student projects it might be fine but in long run you will have to learn DBMS and Database design techniques. Some known databases are MS SQL, MySQL, Oracle, DB2 etc. Since you are working with Visual studio so i will suggest that you should install MS SQL free edition.
The more you start working with the latest technologies, the more ways you will find to create a database. Latest technologies add some sort of abstraction, so initially, just focus on creating a database in DBMS.
How to secure the database from others to open it?
Well, you need some sort of book to understand the database first.
In real world scenario's, mostly, the database is on a secured server and only database administrators have rights to change things in it. Developers usually have read only rights and they request the admins to run scripts the database. Secondly, the database that the developers get is usually encrypted i mean clients almost never give real data to the developers for security point of view.
Lastly, if you are using MS SQL then your database is always behind some sort of security like the Login box initially.
How to create a database programmatically?
Well, there are ways but since you are new you should try them for now. Post your problem here, and people will guide you with some easy way to achieve your task.
In the end, forums are great way to learn things. I do the same by asking questions to seniors. Keep it up and welcome to SO and programming, you will enjoy this community.
Welcome to SO. As written in comment you need to start with a good book, I an sure you can something online.
One suggestion is to always first check Google. For example, searching for your third question brings up several results, and going through even the first couple will give you all the information you need.
When you have a specific question, ask here along with some code showing what you have tried and make your best attempt creating an SSCCE. I assure you the answers will be quick.
1. How to create the database? - is there a correct way for always?
There is no correct way for always for anything. Most software create database programmatically, since you cannot expect your users to create the correct schema for you. This is typically either done in an installer or at start up.
2. How to secure the database from others to open it?
There isn't any easy solution to this. One option is to ask the user for a password when creating the database and then again the ask the user every time they run the program. Some databases allow creating an encrypted properties files for starting the database server specifying a password.
In general, security is a very big topic. Again, a google search brings up interesting material but with less definitive guidelines
3. How to create a database programmatically?
Check Google. This is a specific question but you should be able to find out the answer for yourself quite easily.
Related
I have been creating a database that will handle tutor and student information. Students will be able to access information about the tutors and the database itself will be able to track the students that come in for tutoring sessions (i.e. demographic information and major information as well as attendance). I have a good database created but now I need a GUI to go with it.
Last semester I programmed window form applications in c# with visual studios (2017) and I think this would be a great application to create a GUI with for this database. I am sure there is a way to connect my database to visual studio but I am not sure the commands that would be executed or the certain steps that take place inside visual studio (adding a file? reference?).
I am looking for one of two solutions. We have sql developer available on a school network that can be accessed via IP and student user/pass. I could connect the c# application to that database, but then it would only work while i am on the campus network (which is fine because thats where the application will be used). I cannot find any documentation on how to go about this, perhaps its not possible yet.
The other solution I foresee is creating a local database on my computer for the application which would work fine as well, as long as I can use the script that I have made already, if this is the case I just need to know how to connect the C# code to the local database (I am guessing to create a local database there is an option just like there is a windows form application, it would be a local database supporting pl/sql).
Anyways I would greatly appreciate any help given. If you can point me to some documentation or explain yourself IT would be a big help to me and my final grade (and the tutoring center).
Thanks all!
TL:DR Need a way to connect C# code to database either local or on school network.
GUI:
So first off, in terms of what you should do for your GUI with C#, I would recommend WPF. It is newer and more supported by Microsoft than Windows Form Application.
SQL:
For your SQL connection it really depends on your type of database. I recommend you search the NuGet package library as there are connectors for almost every type of DB. I know .Net comes with a general connector, but personally with my MySQL DB I had the most luck with the MySQL connector in NuGet.
More Help:
Also based off of your tag oracle-sqldeveloper, I assume you are using MySQL. If you are a great C# guide can be found here. I used this and it really helped in getting me started with MySQL & C#.
i developed C# application for windows the back end is mysql database but the problem is, if i want to run it in different computer it requires mysql server software or other wise it cant open the data base. is there any way to add plugins to the s C# application or adding open source software to my installation package to run the database file. please note i'm new to C# this is for education purpose sorry for if my questions asking method is not professional.
Front end : visual studio 2013
Back End : Mysql server 2008
I dont know if i got your question right but i assume it a general Data Access Layer strategy question.
If you "bind" your application with mySQL or any other db then that's it.
Depending on the size of the application you could use open source db like SQLite It is a one file db that can be stored with your application.
If you really want to be able to use your software with many underlying DBs then you have alot of job.
THIS question in SO debates that maybe it is not a good idea or at least it is a partially good idea. Partially means that you could abstract basic db behavior to be db independent but you will not get rid off the dependencies 100%
Another good approach would be to use an ORM. Either a micro ORM like dapper or afull ORM like Nhibernate
ORMs let you do just that. You can use an OleDb provider and have access to many underlying sources at a cost of course of not using 100% the native capabilities of the DB....
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.
I have deployed plenty of software to my clients. Mostly are Window Forms applications.
Here is my current practice.
Manually install SQLExpress and SQL Management Studio to each client PC.
Then use ClickOne to install the code from the server.
When there is a changes in code, I will use ClickOne to deploy -(NO PROBLEM with this step)
But when there is a change in a database column, what do I do?
I have even tried writing a database update script. Each time the program starts, it will read through the .sql update file and run them if the database exists. This solves the problem of updating the database columns, but it does not help in my DEBUGGING work when my customer complain there is a wrong data. At that point, I have to personally go to their site to check it out.
I find it difficult to have the database installed on the client PC as it make my debugging work very very difficult. I am thinking about moving my client database to a host on an Online server. But that then comes with these constraints:
What if the internet is down?
What if my customer has no internet?
Could you help to advise me? Is this a common problem faced by developer? What is the common practice out there? Does Window Azure or SQL CE help?
Depending on the data I would recommend using SQL CE.
If the data isn't too much, speed is not the primary goal (CE is slower than Express) and you don't need DB-Features not supported by CE (e.g. stored procedures) it is the better choice IMHO, because:
The client does not need to install a full SQL server (easier installation/deployment)
You do not have problems with multiple SQLExpress instances
Your SW doesn't need to worry if there even is a SQL instance
Less resources used on the client side
Additionally the clients could send you their SQL CE DB-File for inspection and you do not need to go to their site.
It is also relativly easy to implement an off site sync with SQL CE and MS Sync FW.
Installing one database per client PC can be tricky. I think you have a decent handle on how to deal with the issue currently. It seems like the real issue you are currently facing is debugging. To deal with this, there are a couple ways you could go:
Have the customer upload their copy of the database back to you. This would provide you with the data they have and you could use it with a debug copy of your code to identify the issues. The downside is that if the database is large it might be an issue transferring it.
Remote onto the customer's machine. Observe the system remotely using something like CoPilot. That way you could see what is happening in its natural environment.
There are probably other ways, but these are a couple of good ones. As for using an online database, this is an option but it brings its own set of issues with it. You mentioned a couple. As for Azure, that is cloud-based (online) so the same issues will apply. SQL CE won't help you any more than your current installation does.
Bottom line is that I would recommend you look into the ways to fix your one issue (as listed above) instead of creating a whole new set of issues by moving to an Internet-based solution. I would only recommend moving to the Internet if it was addressing a larger business need (for example, mobility). Doing the same thing you have been doing only online will probably just make life harder.
To recap the comments below since they are so pertinent to the issue, if you are choosing between file-based databases that don't need to be physically installed on the machine, your best choices are probably between SQLite and SQL CE. Microsoft supports SQL CE better but it is a larger package and has less features than the trim SQLite. Here is a good discussion on the differences:
https://stackoverflow.com/questions/2278104/sql-ce-sqlite-what-are-the-differences-between-them
However, the issue gets more complicated when you start looking at linq2sql since that is designed for SQL server. Microsoft does not support SQL CE with linq2sql out of the box, although there is a work-around that will get it to work:
http://pietschsoft.com/post/2009/01/Using-LINQ-to-SQL-with-SQL-Server-Compact-Edition.aspx
SQLite is not supported at all with linq2sql but there is a way to use linq to talk with SQLite:
LINQ with SQLite (linqtosql)
This library also supports other common databases including MySQL and Firebird.
You could use the SQLCMD utility to execute the change script, as mentioned in this related question
I've added a service based database to my solution.
So, it's working on my system and everything is dandy. However this program will have to run on many many machines all independent to each other (meaning they don't connect or even know they exists) I'm selling the application to different people all over my country.
What exactly do I have to do so my application has access to the database design and uses it?
I might be asking the wrong question, but hopefully with my use case you can guide me. Thanks!
You will need to install the relevant database engine with the correct service name, and create the database and relevant objects on installation.
Overall probably not a good solution unless you really need a fully fledged database engine, and even then i local database might be easier.
Bear in mind that the installation of a serious database engine often has complication which would baffle the average PC user.
Can't you use something like sqllite, or berkelydb?
What exactly are the requirements?