473,378 Members | 1,140 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 2111
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
by: Patchwork | last post by:
Hi Everyone, Please take a look at the following (simple and fun) program: //////////////////////////////////////////////////////////////////////////// ///////////// // Monster Munch, example...
6
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
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
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
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
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
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
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
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
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.