views:

46

answers:

3

I know mysql, and I'd like to learn sqlserver. I'm currently stuck on the basics of basics:

  1. How to install and configure sql server
  2. How to connect to it

I installed Sql Server through Web Platform Installer, and have Visual Studio 2008 installed. Still, I can't understand how to connect to my server:

  1. I see that the SQL service itself (SQLEXPRESS) is running in both in services.msc and Sql Server Configuration Manager
  2. I try to connect to it via the Management Studio, but I don't understand what to do.

Where do I begin?

+2  A: 

Start Management Studio and Select Database Engine as your SqlExpress instance then choose Windows Authentication and press connect. After that in object explorer you will see your databases if you want to create one right click databases and create new one.

You can look at http://msdn.microsoft.com/en-us/library/ms186312.aspx

Xenon
I don't any local servers. What server name do I use?
ripper234
Thanks for the link - I just had to enter ".\sqlexpress" as the server name.
ripper234
+1  A: 

There are two types of ways you can install a SQL Server instance: 1. Named Instance 2. Default Instance

When you use the default instance, and it's the only instance on the machine, the server would listen directly on the port 1433 which is the default SQL Server port. This is what you'd expect if you come from a mysql background.

When you "name" an instance, such as SQLEXPRESS, it works differently. You connect to a special service (SQL Server Browser Service) which now listens on that port, and points the client to the "correct" port of the named instance. I hope I'm being accurate about this one, but that's what happens in general.

You could connect directly to the named instance if you see what port it binds to in the SQL Server error log, and if you could choose the port in the client application.

Read more about this here: http://msdn.microsoft.com/en-us/library/ms181087.aspx

shlomoid
I installed SQLExpress from the "Web Installer" and next-nexted it.
ripper234
A: 

To connect to SQL Server, you need to create a connection string such as below:

private SqlConnection connection; private string connectionString = @"Server=(local);Database=Embedding_SQL_Test;User ID=sa;Password=123"; connection = new SqlConnection( connectionString );

Next, you use the SqlConnection object created above to create a 'SqlCommand', as shown below: SqlCommand cmd = new SqlCommand( "select * from Customer where CustomerID = @Cid", connection);

The SQL query shown here can be replaced by a SELECT, INSERT, UPDATE queries etc.

Next to execute the SQL queries in the database, you use the following methods: ExecuteReader - to execute SELECT queries ExecuteNonQuery - to execute INSERT, DELETE, UPDATE, and SET statements.

This is a very short description of how to connect to SQL Server database from C# and execute SQL queries in the database. For details about the connection string, the methods and their parameters check the following link: ( http://www.shahriarnk.com/Shahriar-N-K-Research-Embedding-SQL-in-C-Sharp-Java.html ) Here you will also find details about how to pass parameters to the SQL queries as well as calling stored procedures and much more.