LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   mono SQL Server Connectivity Issue (https://www.linuxquestions.org/questions/programming-9/mono-sql-server-connectivity-issue-761572/)

aeman 10-13-2009 06:07 AM

mono SQL Server Connectivity Issue
 
Hi,

I try to run a C# code on CentOS5 using mono version is 1.2.4. I compile my code by issuing command on terminal
#gmcs Program.exe -r:System.Data

the code compile successfully.

when i run my code by issuing command on terminal
#mono Program.exe
------------------------------------------------------------------------
OUTPUT is:
Wowww //after pressing ENTER

Unhandled Exception: System.Data.SqlClient.SqlException: SQL Server does not exist or access denied
at Syatem.Data.SqlClient.SqlConnection.Open () [0x0000]
at Sqlprob.Program.Main(System.String[] args) [0x0000]
------------------------------------------------------------------------
My code is:
using System;
//using System.Collections.Generic;
using System.Text;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data;

namespace sqlprob
{
class Program
{
static void Main(string[] args)
{

SqlConnection myConnection = new SqlConnection(@"Data Source=ITSECWIN3KSRV09\SQLEXPRESS; Initial Catalog=EMS_Enquirer_Logoinn_Phase2_Dev; User ID=sa; Pwd=admin;");

myConnection.Open();
try
{

if (myConnection.State.ToString() == "Open")
{

Console.WriteLine("Wowww");
Console.ReadLine();
}
else
{
Console.WriteLine("Hooooowwww");
Console.ReadLine();
}

}//end try
catch(Exception ex) {
Console.WriteLine(ex.Message + ex.Source);
}
SqlConnection mycon = new SqlConnection(@"Data Source=ITSECWIN3KSRV09\SQLEXPRESS; Initial Catalog=EMS_Enquirer_Logoinn_Phase2_Dev; User ID=sa; Pwd=admin;");

mycon.Open();
try
{
Console.WriteLine(mycon.State.ToString());
}
catch(Exception ex)
{
Console.WriteLine(ex.Message+ex.Source);

}
}
}

}

Please help me out. I am totally stuck in my application.

Thanks in advance...

ta0kira 10-13-2009 07:26 AM

This really sounds like a problem outside of your program. Have you checked to see if you can access the database outside of your program (e.g. using a client program)? If you're able to do that, the next place to look is the string you pass to make the connection.
Kevin Barry

aeman 10-13-2009 07:55 AM

mono SQL Server Connectivity Issue
 
Thanks for your reply.

Yes First I run my code on Windows .Net framwork. It runs fine.

But when I run my code on CentOS using mono its 1st time connect with server but at very next it throws exception as I indicates in my output.

ta0kira 10-13-2009 10:30 AM

But can you connect on CentOS in the first place (e.g. with a standard client application)? You need to make sure it's even possible the way you have your system set up before you start trying to figure out why it doesn't work for your program.
Kevin Barry

aeman 10-14-2009 01:25 AM

Yes I can connect my application with sql server in the envoirnment of CentOS. I don't think so that their is problem in connection string.
output which I show in my post is actually a runtime of CentOS.

ta0kira 10-14-2009 04:44 PM

I don't know about mono, but postgresql has a default location to look for a socket for local connections. It could be that you have to configure that (or something similar) within the library you use to connect to it.
Kevin Barry

aeman 10-15-2009 12:23 AM

Kevin I have resolved this problem by updating mono installation upto 2.4.2.3 version. Its now working fine.
Thanks for your support
Cheers


All times are GMT -5. The time now is 02:16 AM.