[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=127.0.0.1\\SQLEXPRESS;
Database=mydatabase;User ID=user;Password=password";

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

See http://www.mono-project.com/SQLClient for more info.
 
If 127.0.0.1 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


Hi,

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
direction.

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=127.0.0.1\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[]
buf,
Int32 offset, Int32 size, SocketFlags flags, System.Net.EndPoint remote_end)
in <0x00045> System.Net.Sockets.Socket:ReceiveFrom (System.Byte[] buf,
System.Ne
t.EndPoint remote_end)
in <0x00091> System.Net.Sockets.UdpClient:Receive (System.Net.IPEndPoint
remoteE
P)
in <0x001bc>
System.Data.SqlClient.SqlConnection+SqlMonitorSocket:DiscoverTcpPor
t ()
in <0x00039>
System.Data.SqlClient.SqlConnection:DiscoverTcpPortViaSqlMonitor (S
ystem.String ServerName, System.String InstanceName)
in <0x00110> System.Data.SqlClient.SqlConnection:ParseDataSource
(System.String
theDataSource, System.Int32 thePort, System.String theServerName)
in <0x00161> System.Data.SqlClient.SqlConnection:Open ()
in <0x000e7> GADatabase.GADatabaseLog2:.ctor (System.String
ServerAndInstanceNam
e, System.String UserName, System.String PassWord, System.String Database)

I've tried it on both mono 1.1.15 and 1.1.13.2.

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

cheers in advance,

Simon
--
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
http://lists.ximian.com/mailman/listinfo/mono-devel-list
-------------- 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