[Mono-dev] Problems connecting to MS SQL with C# and Mono

Daniel Morgan monodanmorg at yahoo.com
Mon May 22 17:37:54 EDT 2006

If you know the TCP port, use it in your connection string.
Do you have the ability to connect to SQL Server using TCP/IP.  By default, SQL Server 2005 Express has this turned off --- which is good from a security standpoint.
See my two backslashes below.
string ConnectionString = "Data Source=\\SQLEXPRESS;
Database=mydatabase;User ID=user;Password=password";

Here, I am using TCP port to connect.
string ConnectionString = "Data Source=,1433;
Database=mydatabase;User ID=user;Password=password";

See http://www.mono-project.com/SQLClient for more info.
If does not work, try localhost.  Or actually try your machine name.
Or you firewall could be blocking the port.

----- Original Message ----
From: muppetboy <simon.harding at iname.com>
To: mono-devel-list at lists.ximian.com
Sent: Monday, May 22, 2006 11:33:32 AM
Subject: [Mono-dev] Problems connecting to MS SQL with C# and Mono


I've tried looking for a solution to this, but not found anything. 
Hopefully someone on this list will be able to point me in the right

I get a horrible exception when attempting to connect to an MS SQL Express
server from Mono (it works under the MS CLR).  

Here is the code I use to make the connection:

string ConnectionString = "Data Source=\SQLEXPRESS;
Database=mydatabase;User ID=user;Password=password";

SqlConnection DatabaseConnection = new SqlConnection(ConnectionString);
DatabaseConnection.Open(); //Exception thrown here

The exception I get is:

System.Net.Sockets.SocketException: Connection reset by peer
in <0x0008f> System.Net.Sockets.Socket:ReceiveFrom_nochecks (System.Byte[]
Int32 offset, Int32 size, SocketFlags flags, System.Net.EndPoint remote_end)
in <0x00045> System.Net.Sockets.Socket:ReceiveFrom (System.Byte[] buf,
t.EndPoint remote_end)
in <0x00091> System.Net.Sockets.UdpClient:Receive (System.Net.IPEndPoint
in <0x001bc>
t ()
in <0x00039>
System.Data.SqlClient.SqlConnection:DiscoverTcpPortViaSqlMonitor (S
ystem.String ServerName, System.String InstanceName)
in <0x00110> System.Data.SqlClient.SqlConnection:ParseDataSource
theDataSource, System.Int32 thePort, System.String theServerName)
in <0x00161> System.Data.SqlClient.SqlConnection:Open ()
in <0x000e7> GADatabase.GADatabaseLog2:.ctor (System.String
e, System.String UserName, System.String PassWord, System.String Database)

I've tried it on both mono 1.1.15 and

Any ideas what I'm doing wrong? Or is this a mono issue?

cheers in advance,

View this message in context: http://www.nabble.com/Problems+connecting+to+MS+SQL+with+C-+and+Mono-t1663529.html#a4507372
Sent from the Mono - Dev forum at Nabble.com.

Mono-devel-list mailing list
Mono-devel-list at lists.ximian.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20060522/cbc0423b/attachment.html 

More information about the Mono-devel-list mailing list