Hi, Everyone
I am trying to connect to an SQL 2000 server in c# using a windows application. What I'm trying to do is ask the user to type in the server name and from the user's input take that server name that they enter in and connect to that server. i also want them to enter a user name and password (SQL authentication) and hide their connection string. Here is my code:
Can some please help me, I don't understand why I can't connect to the sql server when the user provides the server information?
Thanks
I am trying to connect to an SQL 2000 server in c# using a windows application. What I'm trying to do is ask the user to type in the server name and from the user's input take that server name that they enter in and connect to that server. i also want them to enter a user name and password (SQL authentication) and hide their connection string. Here is my code:
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.SqlTypes;
namespace WindowsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection connection = new SqlConnection();
connection.ConnectionString = "Server=" + textBox1.Text + ";User ID=;PWD=;database=";
connection.Open();
SqlCommand thisCommand = connection.CreateCommand();
textBox1.Text = "Connected";
//create dataset to hold rows, columns, etc
DataSet dataset = new DataSet();
connection.Close();
}
private void get_tables()
{
// DataTable tables = new DataTable("Tables");
// using (SqlConnection connection =
//new SqlConnection(connectionString))
//SqlCommand command = connection.CreateCommand();
//command.CommandText = "select table_name as Name from
// INFORMATION_SCHEMA.Tables where TABLE_TYPE =
// 'BASE TABLE'";
// connection.Open();
// tables.Load(command.ExecuteReader(
// CommandBehavior.CloseConnection));
}
}
}
Thanks
Comment