473,503 Members | 3,866 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple ADO problem

I run the following and I get a messagebox telling me the connection
is closed (OK so far) and then it crashes. The error message is: SQL
Server does not exist or access denied.

SQL Manager is running and I tested it by running an older ADO
assignment (which worked). So I'm not sure what I'm doing wrong with
the following bare-bones code...

My code follows.
===
using System;
using System.Windows.Forms;
using System.Data.SqlClient;

public class ConnectionTest
{
public static void Main()
{
try
{
SqlConnection myConnection = new SqlConnection("Initial
Catalog=Northwind;Data Source=localhost;Integrated Security=SSPI;");
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);
}
}
}
Nov 16 '05 #1
9 2124
Alex <a@b.c> wrote in
news:du********************************@4ax.com:
I run the following and I get a messagebox telling me the
connection is closed (OK so far) and then it crashes. The error
message is: SQL Server does not exist or access denied.

SQL Manager is running and I tested it by running an older ADO
assignment (which worked). So I'm not sure what I'm doing wrong
with the following bare-bones code...


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)
- Change your connection string to use a username/password
instead of integrated security.
- 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.
- Check out www.connectionstrings.com for some more tips.

Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 16 '05 #2
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);
}
}
}
Nov 16 '05 #3
Alex <a@b.c> wrote in
news:1g********************************@4ax.com:
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):

string connectionString = "Integrated
Security=SSPI;Persist
Security Info=False;Initial Catalog=CI632Appointments;Data
Source=alex-jayme\netsdk";


Alex,

The \n is causing the error. That puts a newline in the string.
Either escape it (\\n), or precede the entire string with the @
symbol (e.g. @"Integrated Security;Persist...")

Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 16 '05 #4
On Fri, 09 Apr 2004 02:15:40 -0700, "Chris R. Timmons"
<crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote:
The \n is causing the error. That puts a newline in the string.
Either escape it (\\n), or precede the entire string with the @
symbol (e.g. @"Integrated Security;Persist...")


Thank you very much! That's what I get for writing VB for too long...

One more question, though. How do I get the host name without typing
it? If I type it out, no errors, and everything performs as expected
but if I use "Data Source=localhost" or "Data Source=(local)" I get
the error again ("SQL Server does not exist or access denied.").
Nov 16 '05 #5
Alex <a@b.c> wrote in
news:oe********************************@4ax.com:
On Fri, 09 Apr 2004 02:15:40 -0700, "Chris R. Timmons"
<crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote:
The \n is causing the error. That puts a newline in the string.
Either escape it (\\n), or precede the entire string with the @
symbol (e.g. @"Integrated Security;Persist...")


Thank you very much! That's what I get for writing VB for too
long...

One more question, though. How do I get the host name without
typing it? If I type it out, no errors, and everything performs
as expected but if I use "Data Source=localhost" or "Data
Source=(local)" I get the error again ("SQL Server does not
exist or access denied.").


Alex,

I'm not sure why the "localhost" or "(local)" name won't work for
you. Here's a Google thread that seems to cover most of the possible
causes:

http://groups.google.com/groups?hl=e...=UTF-8&oe=UTF-
8&threadm=xUxM0SWFEHA.1988%40cpmsftngxa06.phx.gbl& rnum=51&prev=/group
s%3Fas_q%3D%2522sql%2520server%2522%2520(local%252 0OR%2520localhost)%
2520connection%26safe%3Dimages%26ie%3DUTF-8%26oe%3DUTF-
8%26as_ugroup%3Dmicrosoft.*%26as_scoring%3Dd%26lr% 3D%26num%3D100%26hl
%3Den

or

http://tinyurl.com/2od46
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 16 '05 #6
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);
}
}
}
Nov 16 '05 #7
Alex <a@b.c> wrote in
news:1g********************************@4ax.com:
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):

string connectionString = "Integrated
Security=SSPI;Persist
Security Info=False;Initial Catalog=CI632Appointments;Data
Source=alex-jayme\netsdk";


Alex,

The \n is causing the error. That puts a newline in the string.
Either escape it (\\n), or precede the entire string with the @
symbol (e.g. @"Integrated Security;Persist...")

Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 16 '05 #8
On Fri, 09 Apr 2004 02:15:40 -0700, "Chris R. Timmons"
<crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote:
The \n is causing the error. That puts a newline in the string.
Either escape it (\\n), or precede the entire string with the @
symbol (e.g. @"Integrated Security;Persist...")


Thank you very much! That's what I get for writing VB for too long...

One more question, though. How do I get the host name without typing
it? If I type it out, no errors, and everything performs as expected
but if I use "Data Source=localhost" or "Data Source=(local)" I get
the error again ("SQL Server does not exist or access denied.").
Nov 16 '05 #9
Alex <a@b.c> wrote in
news:oe********************************@4ax.com:
On Fri, 09 Apr 2004 02:15:40 -0700, "Chris R. Timmons"
<crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote:
The \n is causing the error. That puts a newline in the string.
Either escape it (\\n), or precede the entire string with the @
symbol (e.g. @"Integrated Security;Persist...")


Thank you very much! That's what I get for writing VB for too
long...

One more question, though. How do I get the host name without
typing it? If I type it out, no errors, and everything performs
as expected but if I use "Data Source=localhost" or "Data
Source=(local)" I get the error again ("SQL Server does not
exist or access denied.").


Alex,

I'm not sure why the "localhost" or "(local)" name won't work for
you. Here's a Google thread that seems to cover most of the possible
causes:

http://groups.google.com/groups?hl=e...=UTF-8&oe=UTF-
8&threadm=xUxM0SWFEHA.1988%40cpmsftngxa06.phx.gbl& rnum=51&prev=/group
s%3Fas_q%3D%2522sql%2520server%2522%2520(local%252 0OR%2520localhost)%
2520connection%26safe%3Dimages%26ie%3DUTF-8%26oe%3DUTF-
8%26as_ugroup%3Dmicrosoft.*%26as_scoring%3Dd%26lr% 3D%26num%3D100%26hl
%3Den

or

http://tinyurl.com/2od46
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 16 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3659
by: Patchwork | last post by:
Hi Everyone, Please take a look at the following (simple and fun) program: //////////////////////////////////////////////////////////////////////////// ///////////// // Monster Munch, example...
6
2122
by: francisco lopez | last post by:
ok , first of all sorry if my english is not so good, I do my best. here is my problem: I donīt know much javascript so I wrote a very simple one to validate a form I have on my webpage. ...
0
1871
by: 42 | last post by:
I implemented a simple class inherited from Page to create a page template. It simply wraps some trivial html around the inherited page, and puts the inherited page into a form. The problem I...
18
1486
by: Sender | last post by:
Yesterday there was a very long thread on this query. (You can search on this by post by 'sender' with subject 'Simple Problem' post date Oct 7 time 1:43p) And in the end the following code was...
27
4583
by: one man army | last post by:
Hi All- I am new to PHP. I found FAQTS and the php manual. I am trying this sequence, but getting 'no zip string found:'... PHP Version 4.4.0 $doc = new DomDocument; $res =...
2
5170
by: Vitali Gontsharuk | last post by:
Hi! I have a problem programming a simple client-server game, which is called pingpong ;-) The final program will first be started as a server (nr. 2) and then as a client. The client then...
8
3529
by: rdrink | last post by:
I am just getting into pysqlite (with a fair amount of Python and MySQL experience behind me) and have coded a simple test case to try to get the hang of things... yet have run into a 'stock...
5
1870
by: Chelong | last post by:
hey,the follow is the text file content ========================================apple====pear== one Lily 7 0 0 7 7 two Lily 20 20 6.6666 20 8 one Lily 0 10 2.85 4 0 two Lily 22 22 7.33326 2 5 ...
30
3472
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7291
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7357
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7012
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3171
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
402
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.