On Wed, 07 Apr 2004 23:06:33 -0700, "Chris R. Timmons"
<crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote:
Alex,
Your code works fine on my machine.
Some things to try:
- Make sure you have SQL server set up to use either integrated
or mixed-mode security (see "mixed mode security" in
the SQL server books online for more info)
I'm using the neutered sqlmangr.exe version (not the real SQL Server).
But, I don't think this is the problem...
- Change your connection string to use a username/password
instead of integrated security.
I want to make this secure and generic but, again, I don't think this
is the problem...
- Use the MS Data Connection editor to build and test a
connection string. If you don't have Visual Studio, you
can invoke the editor by creating an empty file with a "UDL"
file extension. (that extension is registered with the
editor). Double-clicking on the file will bring up the
Data Connection editor. The connection string you build will
be saved to the UDL file in INI format.
I did that - that's how I ended up with my connection string. I also
pressed the "test connection" button with no errors/warnings.
- Check out www.connectionstrings.com for some more tips.
What's really weird is that, in VB, this same code seems to work. So
I'm left with the conclusion that my C# code must be at fault yet you
have told me my code works fine.
My code again (different version but still giving me the same
problem):
===
using System;
using System.Windows.Forms;
using System.Data.SqlClient;
public class ConnectionTest
{
SqlConnection(connectionString);
public static void Main()
{
try
{
string connectionString = "Integrated Security=SSPI;Persist
Security Info=False;Initial Catalog=CI632Appointments;Data
Source=alex-jayme\netsdk";
SqlConnection myConnection = new
SqlConnection(connectionString);
MessageBox.Show("Connection is " +
myConnection.State.ToString());
myConnection.Open();
MessageBox.Show("Connection is " +
myConnection.State.ToString());
myConnection.Close();
MessageBox.Show("Connection is " +
myConnection.State.ToString());
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}