Home > Archive > C# > March 2004 > SqlConnection Request Failed
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
SqlConnection Request Failed
|
|
| Simone P. 2004-03-28, 10:29 pm |
| Hi!
I must connect to a sql Server 2000 on another machine, in the same
lan. I use VS .Net C# to write program code.
I have compile this sample program:
"
using System;
using System.Data.SqlClient;
class FirstExample
{
public static void Main()
{
try
{
SqlConnection mySqlConnection =
new SqlConnection(
" server=localhost;database=Northwind;uid=
sa;pwd=sa"
);
SqlCommand mySqlCommand = mySqlConnection.CreateCommand();
mySqlConnection.Open();
}
catch (SqlException e)
{
Console.WriteLine("A SqlException was thrown");
Console.WriteLine("Number = "+ e.Number);
Console.WriteLine("Message = "+ e.Message);
Console.WriteLine("StackTrace:\n" + e.StackTrace);
}
}
}
"
Naturaly in the sqlConnection I have insert my server, my db, my uid
and pwd.
When I run this code, appeare an exception
"Request Failed"
and I see, when I make a debug mode, the creation of istance mySqlConnection
raise this exception.Why?
it's strange because this code is taken on a C# Programming book,naturally
the SQL Server work correctly and .NET Version is 7.0.9466 and
..NET Framwork 1.0 Version 1.0.3705, but I can't upgrade to the last
version :(
Sorry for my english.
| |
| Dincer Ozturan 2004-03-28, 11:32 pm |
| In the beginning of your message you tell that you'd like to connect
to a sql server 2000 on another machine but in your connection string
you've written "server=localhost;". Probably if you write the server
instance name that is located in the other machine, the problem will
be fixed. If you encounter problems after changing the server name,
then create a .udl file on your desktop and open it. Then fill the
server name, server type, username, password and select the database
you wish to connect to. Then Press "Test Connection" button. If Test
does not succeed, you should call your network administrator. If test
succeeds, then close the window. Open .udl file with Notepad. The
succeeding Connection String will be right out there.
Dincer Ozturan
"Simone P." <hokusNOSPAM@emailNOSPAM.it> wrote in message news:<3SI3c.2577$5h5.1799@tornado.fastwebnet.it>...
> Hi!
>
> I must connect to a sql Server 2000 on another machine, in the same
> lan. I use VS .Net C# to write program code.
> I have compile this sample program:
>
> "
> using System;
> using System.Data.SqlClient;
>
> class FirstExample
> {
> public static void Main()
> {
> try
> {
> SqlConnection mySqlConnection =
> new SqlConnection(
>
> " server=localhost;database=Northwind;uid=
sa;pwd=sa"
> );
>
> SqlCommand mySqlCommand = mySqlConnection.CreateCommand();
>
> mySqlConnection.Open();
> }
> catch (SqlException e)
> {
> Console.WriteLine("A SqlException was thrown");
> Console.WriteLine("Number = "+ e.Number);
> Console.WriteLine("Message = "+ e.Message);
> Console.WriteLine("StackTrace:\n" + e.StackTrace);
> }
> }
> }
> "
>
> Naturaly in the sqlConnection I have insert my server, my db, my uid
> and pwd.
> When I run this code, appeare an exception
> "Request Failed"
> and I see, when I make a debug mode, the creation of istance mySqlConnection
> raise this exception.Why?
> it's strange because this code is taken on a C# Programming book,naturally
> the SQL Server work correctly and .NET Version is 7.0.9466 and
> .NET Framwork 1.0 Version 1.0.3705, but I can't upgrade to the last
> version :(
> Sorry for my english.
|
|
|
|
|