I need a database for a web project (and for off-line projects as well). The problem is I don't know where to start and googling returns more advanced stuff. Where do I start?
I already have Visual Studio 2010 and Visual Web Developer 2010 installed (both – the express version). I'm not sure I have what is needed for SQL (which, correct me if I'm wrong, is what I need for databases). In my start button I have two folders named "Microsoft SQL Server 2008" (one of them with an "R2" at the end). But my computer isn't a server, just a PC. Am I supposed to install something on my PC? If so – which of the two? (The one with the "R2" or the one without it)
All I need is to create a simple database so I can store and retrieve information easily instead of reading a text file....
well, you need SQL Server installed. Try searching your computer for it, you may have it installed. The easiest way is to run services.msc and look for SQL Server.
See here, I have 3 instances installed but just one running (INSTANCE2008 is the name I gave to it, you will probably have SQLEXPRESS or MSSQLSERVER):
If it is installed you will need SQL Server Management Studio to create your database. You will probably have it under:
once you access it, just connect to your server (usually called localhost), right click on the database folders and select "new database"
from that, it is really easy to create your DB, just follow the steps
Sounds like you have all the tools you need to get started, however you might also need SQL Management Studio as well.
But "How to start creating and using databases?" is sort of a broad question. If your question is really about application design, then you would start 'creating databases' when you've defined your model. Once your model is defined, then you can start creating the database.
If your question really is about creating and using databases, SQL Management Studio should get you on the right track. It's a point n' click way to creating databases, tables, stored procs, etc.
Using the database... hmmm. The easiest way is to integrate Microsoft's Enterprise Library 5. Again, point n' click interface to setting up the connection in your web.config (or app.config) and plenty of examples.
You can import the System.Data and System.Data.SqlClient library in your application, like
using System.Data;
using System.Data.SqlClient;
and research about the SqlConnection class.
about SQL Statements, the W3Schools has a good reference.
A simple method sample that has a connection
protected void connection()
{
using(SqlConnection conex = new SqlConnection("your_connection_string"))
{
SqlCommand comand = new SqlCommand();
comand.CommandText = "SELECT * FROM Table";
comand.CommandType = CommandType.Text;
comand.Connection = conex;
conex.Open();
comand.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter(comand);
DataTable dt = new DataTable();
da.fill(dt);
}
}
You will be having your database on your server. You can directly connect to that database with just a slight configuration in web.config.
OR
If you found "SQL Server Management Studio" in your Microsoft SQL Server 2008 R2 click on it and login to the sql server / express instance of the sql server.
Create the database there.
Related
Hey IO have an old access data base and I have reeated the New data base using SQL Server Management Studio but all the data is still in the Access data base and I was wondering how to link these two. I have been trying to create the linked tables in access using the ODBC tool but none of the table I want are appearing?
Was wondering if anyone has any ideas on how I can do this?
Also I then have started to create the front end of the database using Visual Studio but cant get the fields to populate as the SQL database currently has no data linked to it
Instead of linking tables have you considered using SQL Server Express (you did not mention what the 'new database' is, assume Access?) and the data import wizard to port the data to SQL Server? You get all the tools by downloading 'SQL Server with tools' from Microsoft. And use SSMS for management functions, it is much easier than the Visual Studio interface.
I've started working on my database desktop application. The goal is to have one centralized database, so that each employee could connect.
My goals:
Centralized database on SQL Server 2008 Express
Use Sql to Linq
First run of application should create structure of database on server.
Now my question: how to do the last point?
I know that I can generate sql script via SQL Managment Studio and then execute it, but maybe there is some better way?
Like the comments said, I'm not sure why you would want to do this, but if you have one centralized database machine and you want to create a new database per user upon the first connection, then you could create one canonical/template database and the clone it via scripting on the first connect.
Your UI would say something like "Please wait while we create your new database..." and you'd run CREATE scripts for the database/tables/stored procedures/views/etc.
Just remember it might be a major pain to update the schemas of these databases once the cat is out of the bag.
In SQL Server Management Studio, there is an option to 'Generate Scripts'. The way we currently transfer a 2008 sql server database to a 2005 sql server database is by generating the scripts and running SQLCMD on that sql script file to push to a local instance of 2005 sql server. I'm creating a C# program to do whole bunch of other tasks as well but I also need it to convert the 2008 database and move it to a 2005 sql server. Is there a Transact sql statement or an easier way to convert the 2008 database to a 2005 database? Thanks.
Your development deliverable should not be a database binary (the .MDF file), but a deployment script. You treat your database deployment and upgrade just like any other source file, place it under source control, have peer code reviews at check in etc etc. Modifying directly the .MDF and then reverse engineering to deploy it is just plain bad. The problem you encountered now is just one of the problems, and there are many more problems, specially around the issue schema changes done during an application version upgrade. See Version Control and your Database.
Now is true that the entire VS tool set is trying to guide you down the path of 'just edit your MDF in the VS Database Explorer and everything will be fine'. Nothing will be fine and one or more deployment meltdowns are just ahead in your life, but lets pretend that VS does a good thing.
You can automate the extraction of the current schema and deployment of it via 3rd party commercial tools like Red Gate's SQL Compare, or you can roll your own 'Generate Scripts' fairly easy. SSMS all it does it invokes the SMO scripting capabilities to script out an entire database. You can do the same: instantiate a Scripter object instance, then add to it the objects you want scripted, then extract the T-SQL generated script. That is exactly what 'Generate Scripts' in SSMS does. There is an example in MSDN for scripting:
//Connect to the local, default instance of SQL Server.
Server srv = new Server();
//Reference the AdventureWorks2008R2 database.
Database db = srv.Databases["AdventureWorks2008R2"];
//Define a Scripter object and set the required scripting options.
Scripter scrp = new Scripter(srv);
scrp.Options.ScriptDrops = false;
scrp.Options.WithDependencies = true;
//Iterate through the tables in database and script each one. Display the script.
//Note that the StringCollection type needs the System.Collections.Specialized namespace to be included.
Microsoft.SqlServer.Management.Sdk.Sfc.Urn[] smoObjects = new Microsoft.SqlServer.Management.Sdk.Sfc.Urn[1] ;
foreach (Table tb in db.Tables) {
smoObjects[0] = tb.Urn;
if (tb.IsSystemObject == false) {
System.Collections.Specialized.StringCollection sc;
sc = scrp.Script(smoObjects);
foreach ( string st in sc) {
Console.WriteLine(st);
}
}
}
Import from one DB in the other
Scripting the database objects out and then running them on the older instance is the way to go. If you have SQL 2008-specific features coded, you'll find it right off when you run the script on 2005 (so test before you try it on Production!).
Setting Compatibility Mode will not help here. If I have a (2008) declared table type and I use it with stored procedure parameters, there's nothing SQL or anyone else can do to migrate it to 2005. Using "modern" systems to support legacy systems is ugly at best.
Just 'cause I'm doing it again, my preferred migration path is:
Have development, "staging", and production environments, all at 2005
Upgrade staging to 2008
Continue developing on dev/2005, and push changes to staging (2008) and production (2005). When it works on 2008 (and it almost certainly will), mgmt will be content with upgrading production. And your 2005 builds will still work on 2005 production.
Upgrade production. Hey, it worked on staging, so it's safe and sane
And everything generated from (2005) development works on (2008) staging and production
And only then do you upgrade development and get to play with your new toys
Imports System.Data.OleDb
Public Class Log
Private mConnectionString As String = "Provider=OraOLEDB.Oracle;Data Source=(DESCRIPTION=(CID=GTU_APP)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=xxx)(PORT=1521)))(CONNECT_DATA=(SID=xxx)(SERVER=DEDICATED)));User Id=xxx;Password=xxx;"
Dim ds As New DataSet
Dim da As New OleDbDataAdapter
Dim dr As DataRow
Dim Connection As New OleDbConnection(mConnectionString)
Dim Command As OleDbCommand
goes on...
That's the code, and it works great on our development machines. We all have the Oracle providers installed on our machines. Now I tried using this code in an app on another machine that does not have the Oracle software installed and it doesn't work.
Now I know I can install the Oracle providers on these other machines and it will work. Problem with that is A) there are many of them and B) I'd have to go through our IT department and it would take six months for them to do it. So my question is, can I connect to this Oracle database from a machine without the Oracle providers installed? I thought Microsoft had it's own Oracle provider but it doesn't show up under System.Data. The .NET version is 3.5 if that helps. Any ideas?
I've had fairly good luck with the Oracle Instant Client and ODP.NET, which is pretty much a straight XCOPY deploy (if you don't need ODBC).
IIRC, you do need to modify the PATH environment variable, but that's relatively painless - especially compared to the hoops Oracle used to make you jump through.
The problem is actually you started a project without discussing the infrastructure needs with your company's IT/DBA team. This is not a technical problem but a process problem.
That being said here is a possible solution (although I haven't used personally).
http://devart.com/dotconnect/oracle/
I'm pretty certain you have to install the Oracle provider in order for this to work. OleDb can easily connect to SQL Server and Access and so on, but only because these providers come pre-installed in Windows.
I think your only option (other than installing the Oracle provider on every machine) is to create a SQL Server "front" database that includes pass-through tables to each Oracle table you need, and then get your data from SQL Server instead of Oracle.
Actually, another option would be to have your client applications get their data from an intermediate web service instead of connecting directly to the database, but this would probably entail a major re-write.
Would it be possible to find and include the Oracle DLLs with your app instead of installing them?
I need to migrate Access databases to SQL Server 2005. Since this needs to be done from within a setup so that a customers' installation is transparently migrated to SQL Server 2005, I wonder if it is possible to automate the SSMA toolkit from Microsoft.
Actually SSMA had command-line interface (special console executable in the SSMA installation folder). It was available at some time but I'm not sure whether it made its way to last release. You should ping SSMA support about what versions had it and what examples of its usages are available. I hope this will help you.
To my own knowledge, such an automation is not available. But it is still possible for you to generate the SQL code that creates the database (the one that will begin with the "CREATE DATABASE" sentence) and launch it through your user interface on your SQL server.
To generate this code, you can
Create the access database with the Access toolkit
Generate the corresponing "CREATE DATABASE" SQL code with (for example) SQL Server Management Studio (right-click on database, choose "script database as CREATE". EMS SQL Studio offers a very nice alternative to SQL Server Management Studio
Save the code for further use
With EMS Studio, You can even decide if this code also updates the data. But I'd prefer to automate data transfer through code: you can for example browse the tables (in the right order, depending on relationships), open recordsets (one local, one SQL), and transfer data by browsing the fields (you do not even need to name them) with code like:
(localRecordset links to local table. can be DAO or ADODB; Adjust code accordingly)
(sqlRecordset links to the SQL server. can be DAO or ADODB; Adjust code accordingly)
localRecordset.moveFirst
Do while not localRecordset.EOF
sqlRecordset.addnew
For each field in localrecordset.fields
sqlRecordset.fields(field.name).value = field.value
Next field
sqlRecordset.update
localRecordset.moveNext
Loop