HI

I installed Visual Studio 2008,but I only installed C#.I want to create new database connection,so what I did is in
Database connection->Add connection->select Data source
But MS Sql server compact 3.5 and MS sql server database File are avaliable in here I cant find the sql native client,only MS Access Database File,So how I connect to remote Sql server?

Once I right click on data connection,the Create new sql server database already disable.
Please help me to slove this problem.

Thanks
Tank50

You can select "SQL Server" to connect to a local or remote SQL Server instance. From the "Data" menu, select "Add New Data Source", select "Database", press "Next", then press "New Connection". In the "Choose Data Source" box that comes up, select "SQL Server". Once you do that, the combobox below will fill with 2 choices - the .NET provider for SQL Server (default) or the .NET provider for OLD DB. Select the .NET Provider for SQL Server, then press "Continue". Now, you can select the database you want to use, and it will build the DataSet and place it into your project.

HI

I did what u said micriscolo,but in there I cant see 2 choices,and there are 3 data source
1.Microsoft Access Database File
2.Microsoft Sql server Compact File
3.Microsoft Sql Server Database File(Something Like that)

I cant browse to network database using above datasource.Please Help me.

Thanks
Tank50

OK, perhaps you don't have the SQL Native Client installed. You can check the Control Panel to see if it is installed (once you open Control Panel, go to "Add or Remove Programs" or "Programs and Features" if you're in Vista).

If it is not, you can download it from here.

Once you have it installed, you should some additional choices for setting up your connection.

Hi

Thanks for fast reply,I download that files also,but I cant see sql native client ,and I installed sql server 2008 ,but nothing happened.
:(

Thanks
Tank50

Just asking, but did you stop and restart Visual Studio after you did the install?

Hi

Yes I closed and reopen visual studio,but I did'nt restart the PC.I check it tommorow.

Thanks
Tank50

Hi

Iam using visual studio 2008 express edition,I feel I cant connect to sql server using visual studio 2008 express edition,but Iam not sure about that

Thanks
Tank50

Some things I'm reading seem to indicate that you cannot use the IDE to create a DataSet that is hooked to a remote SQL Server database. I don't happen to have VS 2008 Express, so I can't test that (the previous example I gave was with the full version of VS2008).

However, in code you should be able to get to the database. Try this code in a test project:
At the top of the module, put:

using System.Data.SqlClient;

In a button_click routine somewhere, put this code:

SqlConnection oConn = new SqlConnection("Server=DBServer;Database=DB;user id=youruser;password=yourpw");
            SqlDataReader myReader = null;
            int count = 0;
            try
            {
                oConn.Open();
            }
            catch (SqlException ex1)
            {
                MessageBox.Show(ex1.Message, "Exception: Open");
                return;
            }
 
            SqlCommand cmd = new SqlCommand("Select * from tb_table", oConn);
 
            try
            {
                myReader = cmd.ExecuteReader();
            }
            catch (SqlException ex2)
            {
                MessageBox.Show(ex2.Message, "Exception: Execute");
                return;
            }
 
            while (myReader.Read())
            {
                count++;
            }
            myReader.Close();
            oConn.Close();
 
            MessageBox.Show("Got " + count.ToString() + " record(s)", "Success!");

Of course, replace the various components (DBServer, DB, youruser, yourpw and tb_table) with values that work in your environment. The success case should be a message box reporting the number of records in the table.

HI

Thanks mcriscolo.But I installed VS 2005 again,I try ur code.


Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.