[Mono-devel-list] ASP.NET and SQL SERVER 2000

rus rus at forgecom.co.uk
Tue Sep 21 07:57:51 EDT 2004


The clue may be in the error message..

The login details are correct?
The server name's correct?
The database name's correct?
The SQL server is allowing connections from the machine running mono?

I've definatly had mono on linux talking to SQL server on windows before
using SqlClient

On Tue, 2004-09-21 at 12:34, falconn at free.fr wrote:
> Hi !
> 
> I've a strange problem with mono. I want to get informations from a database
> under SQL SERVER. I tried the following example taken from the MonoHandbook
> doing some modifications.
> But when I run it, sometimes it's working, sometimes not : it shows an error
> message (something like it can't find the sql server or I don't have access to
> the database). I tried to use unixODBC with freetds and it works, but it's a
> little bit slow! So it doesn't seem to be a problem with my SQL Server. Is it a
> bug?
> 
> 
> 
> Here is the code I use :
> 
> using System;
> using System.Data;
> using System.Data.SqlClient;
> 
>  public class Test
>  {
>     public static void Main(string[] args)
>     {
>   string connectionString =
>      "Server=MyServer;" +
>      "Database=pubs;" +
>      "User ID=MySqlServerUserId;" +
>      "Password=MySqlServerPassword;";
>   IDbConnection dbcon;
>   dbcon = new SqlConnection(connectionString);
>   dbcon.Open();
>   IDbCommand dbcmd = dbcon.CreateCommand();
>   string sql =
>       "SELECT fname, lname " +
>       "FROM employee";
>   dbcmd.CommandText = sql;
>   IDataReader reader = dbcmd.ExecuteReader();
>   while(reader.Read()) {
>   string FirstName = (string) reader["fname"];
>   string LastName = (string) reader["lname"];
>   Console.WriteLine("Name: " +
>        FirstName + " " + LastName);
>   }
>   // clean up
>   reader.Close();
>   reader = null;
>   dbcmd.Dispose();
>   dbcmd = null;
>   dbcon.Close();
>   dbcon = null;
>     }
>  }
> 
> 
> Here is the error message when it doesn't work :
> 
> mono testing.exe
> 
> Unhandled Exception: System.Data.SqlClient.SqlException: SQL Server does not
> exist or access denied.
> in <0x0020e> System.Data.SqlClient.SqlConnection:Open ()
> in <0x00066> Test:Main (string[])
> 
> zsh: exit 1     mono testing.exe
> 
> I have tested the connexion with SQLSharp and the problem remains the same...
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list




More information about the Mono-devel-list mailing list