Error when attempting to connect to SQL from C#

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi all,

Im trying to get a coworker up and running in C# with an SQL connection.
This code works successfully when I connect from my machine to the SQL server:

<pre class="prettyprint using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace ConsoleApplication1
{
class Program
{
SqlConnection myConnection;

Program()
{
// connect to the database
myConnection = new SqlConnection("user id=XXXXXX;" +
"password=XXXXXXXX;server=XXXXXXXX;" +
"Trusted_Connection=yes;" +
"database=XXXXX; " +
"connection timeout=30");
myConnection.Open();
Console.WriteLine(DateTime.Now);
Console.WriteLine("connected");


//this.ConvertData();
}

void ConvertData()
{
List<String> Qs = new List<String>();
Qs.Add("select * " +
"into xxxxx " +
"from yyyyyyyy;");
Qs.ForEach(delegate(String Q)
{
Console.WriteLine(Q);
Console.WriteLine(DateTime.Now); <span class="x_Apple-tab-span" style="white-space:pre SqlCommand myCommand = new SqlCommand(Q, myConnection); myCommand.CommandTimeout = 28800;
SqlDataReader myReader = myCommand.ExecuteReader();
myReader.Close();
myCommand.Dispose();
});
}

static void Main(string[] args)
{
Program p1 = new Program();
Console.WriteLine("done");
Console.ReadLine();
}
}
} [/code]
<br/>
I know for a fact that the log-in information is correct. This code does run on my machine and has run this way successfully for the last 6 months.
When I run this code from her machine, even when using my log-in and password I get this error:
The name MyConnection does not exist in the current context

If MyConnection works perfectly well from my machine, why does it not seem to recognize what its doing on hers?

Is this some type of a network issue? Because her machines has the same network authorizations as mine does on the SQL server.

Thank You!
<h1 style="padding:0px; border:0px; font-size:23px; vertical-align:baseline; font-family:Trebuchet MS,Liberation Sans,DejaVu Sans,sans-serif; line-height:1.3
<br/>
</h1>


View the full article
 
Back
Top