[Mono-devel-list] ASP.NET and SQL SERVER 2000
falconn at free.fr
falconn at free.fr
Tue Sep 21 07:34:53 EDT 2004
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...
More information about the Mono-devel-list
mailing list