Open Connection using C#
Posted by: Maurice Cosgrave
Date: February 23, 2005 11:27AM

I'm writing a pretty simple C# program to connect to a MySQL database which is running on my computer. The code compiles grand, but at the 'mySqlConnection.Open();' line the compiler comes back and says that the 'SqlException was unhandled' and 'Named Pipes Provider: The system cannot find the file specified'.

Any help would be much appreciated - I've posted the code below. I'm using Microsoft Visual C# 2005 Beta to write and compile the code and MySQL version 4.1.10 on WIndows Xp Pro. Cheers.

/*
Performing a SELECT statement using ADO.NET
*/
#region Using directives

using System;
using System.Data;
using System.Data.SqlClient;

#endregion

namespace testConnect1
{
class SqlTest1
{
static void Main()
{
string connectionString = "server=localhost;database=test;uid=denis;pwd=dhoctor";

SqlConnection mySqlConnection = new SqlConnection(connectionString);

string selectString = "SELECT field01, field02, field03 " + "FROM test ";

SqlCommand mySqlCommand = mySqlConnection.CreateCommand();

mySqlCommand.CommandText = selectString;

SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter();

mySqlDataAdapter.SelectCommand = mySqlCommand;

DataSet myDataSet = new DataSet();

mySqlConnection.Open();

Console.WriteLine("Retrieving rows from the Test table");
string dataTableName = "Test";
mySqlDataAdapter.Fill(myDataSet, dataTableName);

DataTable myDataTable = myDataSet.Tables[dataTableName];

foreach (DataRow myDataRow in myDataTable.Rows)
{
Console.WriteLine("Field01 = " + myDataRow["field01"]);
Console.WriteLine("Field02 = " + myDataRow["field02"]);
Console.WriteLine("Field03 = " + myDataRow["field03"]);
}

mySqlConnection.Close();
}
}
}

Options: ReplyQuote


Subject
Written By
Posted
Open Connection using C#
February 23, 2005 11:27AM
February 23, 2005 11:34AM
February 23, 2005 02:46PM
February 23, 2005 02:48PM
February 24, 2005 09:08AM
February 24, 2005 09:40AM
February 25, 2005 12:58AM
February 24, 2005 01:08PM
February 28, 2005 09:20AM
February 28, 2005 09:52AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.