tags:

views:

132

answers:

3

hi

I started learning learning Ado.net and got a bit stuck.

1) If I enable connection statistics via SqlConnection.StatisticsEnabled property, then I should be able to retrieve various information ( via RetrieveStatistics() ) about actions SqlConnection instance performs. Thus, before calling the code below, I already opened a connection and retrieved some values from a database. That way, statistics should provide some information how commands performed. But all values retrieved from the collection return character zero (when converted to string). Any idea why that is?

                ...
 sc.StatisticsEnabled = true;
 IDictionary statistic = sc.RetrieveStatistics();
 Label1.Text = statistic["BytesReceived"].ToString(); //Label1.Text displays 
                                                        character”0”

2) Assuming some PC runs two Sql servers ( MySql server and MS sql server), what names would you use ( in a connection string ) to specify either of the two servers?

thank you

A: 

I can't tell based on you code you have provided, but my very first idea would be that you aren't opening the connection.

As far as you second question, if you were going to have two connection strings and they were on the same box, I would probably say something like [AppName]MySQLConnectionString and [AppName]MSSQLConnectionString

TheTXI
A: 

hi

1)

I can't tell based on you code you have provided, but my very first idea would be that you aren't opening the connection.

I was able to connect to database and retrieve some records, so connection is working. Here is the complete code:

    protected void Page_Load(object sender, EventArgs e)
    {          
        SqlConnection sc = new SqlConnection();
        sc.ConnectionString = @"Data Source=(local)\HEY; " +
             "Initial Catalog=FilmClub; Integrated Security=true";
        SqlCommand scomand = new SqlCommand();
        scomand.CommandText = "SELECT * FROM MemberDetails";
        scomand.Connection = sc;

        sc.Open();
        SqlDataReader sqlreader = scomand.ExecuteReader();

        while (sqlreader.Read())
        {
            TextBox1.Text+= sqlreader["MemberId"].ToString();  
        }


        sc.StatisticsEnabled = true;
        IDictionary statistic = sc.RetrieveStatistics();
        Label1.Text =statistic["BytesReceived"].ToString();


    }

2)

As far as you second question, if you were going to have two connection strings and they were on the same box, I would probably say something like [AppName]MySQLConnectionString and [AppName]MSSQLConnectionString

I’m not sure you understood my question. Say I only have MS Sql server running on my PC. Then my connection string would be the following:

@"Data Source=localhost;Initial Catalog=FilmClub;Integrated Security=true";

But now assume I have both MySQL server and MS Sql server instances running on my computer ( neither of the two servers is a named instance, thus I can’t refer to them via name ). Now what would my connection string be if I wanted to connect to MS Sql server (namely, what would the value of “Data Source=?” attribute be), and what would my connection string be if I wanted to connect to MySql server?

A: 

I can't answer your statistics question as I've never used them, but for the ConnectionString, you would need to use different connection objects.

For example, you can't use a SQLConnection object to connect to a MySQL database. You would need to use a MySQLConnection object (link). You can get information about the different connection string options here.

You can have multiple SQL servers on a single computer and it won't really matter. They all use a different TCP port (SQL 1433, MySQL 3306).

hacker
hiUhm, I totally forgot about different Sql servers using different data providers!So assuming I had several MS SQL servers running on PC, my best option would be to specify (in a connection string) TCP port which particular MS Sql server uses!thanx mate