I think you will need to post your connection string. I do remember having
the same kind of problem once -however one thing to remember is that when
you programatically do it you can have a very basic connection string. That
said the following connection string was taken from the designer property
for connection string and I used it programmatically ok..
this.sqlConnection1.ConnectionString = "workstation id=HOST;packet
size=4096;integrated security=SSPI;data source=HOST;persist security
info=False;initial catalog=Northwind";
this.sqlConnection1.Open();
System.Data.SqlClient.SqlCommand cmd = new
System.Data.SqlClient.SqlCommand("SELECT TOP 10 * FROM
Orders",sqlConnection1);
System.Data.SqlClient.SqlDataReader sr = cmd.ExecuteReader();
if (sr.Read())
System.Windows.Forms.MessageBox.Show(sr[0].ToString());
You will see the following is a very basic connection string (all you
need -bearing in mind you are using Integrated security.
cnn.ConnectionString =
"Data Source =(local);" +
"Initial Catalog=Northwind;" +
"Integrated Security=SSPI";
--
Br,
Mark Broadbent
mcdba , mcse+i
=============
"Alberto" <al*****@nospam.com> wrote in message
news:OZ**************@TK2MSFTNGP09.phx.gbl...
I have an object SqlConnection and I changed the connection string
property in the properties windows. The object works fine but if I do the same
declaring the object connection by code and with the same connection
string property, doesn't work. It can't connect to the database.
What's happening??
Thank you