473,495 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Connection to the DataBase

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
Nov 16 '05 #1
3 1984
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

Nov 16 '05 #2
Hi Alberto,

To make sure you use the right connection string code, you can refer to here:

http://www.connectionstrings.com/

It had many examples on different database and type of connections.

Hope it helps.
--
Regards,
Chua Wen Ching :)
"Mark Broadbent" wrote:
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


Nov 16 '05 #3
Brilliant. However many Favorites I stack up in IE there is always that
extra one that is very useful.
Nice link. Im adding it right now.

--
Br,
Mark Broadbent
mcdba , mcse+i
=============
"Chua Wen Ching" <ch************@nospam.hotmail.com> wrote in message
news:7A**********************************@microsof t.com...
Hi Alberto,

To make sure you use the right connection string code, you can refer to here:
http://www.connectionstrings.com/

It had many examples on different database and type of connections.

Hope it helps.
--
Regards,
Chua Wen Ching :)
"Mark Broadbent" wrote:
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


Nov 16 '05 #4

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

Similar topics

17
3216
by: AMC | last post by:
Hi, I'm using an include file to store the connection string to a database. Whenever I try to reference that string to open a connection in the page that includes the file I get the error 'empy...
11
2396
by: pradeep_TP | last post by:
Hi all, I have a few questions that I have been wanting to ask for long. These are all related to ADO.net and specifically to conenction to database. 1) If I have opened a connection to a...
3
2471
by: R Reyes | last post by:
Hi, I'm trying to modularize my database connections a little better and get more out of my project with less code. First check out this common dbOpen() function inside class clsDatabase. I...
7
2453
by: Lau Lei Cheong | last post by:
Hello, Actually I think I should have had asked it long before, but somehow I haven't. Here's the scenerio: Say we have a few pages in an ASP.NET project, each of them needs to connect to...
3
10270
by: Martin B | last post by:
Hallo! I'm working with C# .NET 2.0, implementing Client/Server Applications which are connecting via Network to SQL-Server or Oracle Databases. To stay independent from the underlaying Database...
35
4803
by: Terry Jolly | last post by:
Web Solution Goal: Have a global database connection Why: (There will be 30+ tables, represented by 30+ classes) I only want to reference the database connection once. I put the connection...
6
3428
by: Arsalan Ahmad | last post by:
Hi all, I am creating a website in which in an Item detail page there are a number of web controls (7 or 8) and what is happening that inside each of control's Page_Load() function I am creating...
5
23975
by: Suresh | last post by:
Hi Guys I have Db2 server installed on remote server. i am connecting to that remote server by using VPN. I want to connect that remote DB2 server instance using my local machine DB2...
20
3237
by: fniles | last post by:
I am using VS2003 and connecting to MS Access database. When using a connection pooling (every time I open the OLEDBCONNECTION I use the exact matching connection string), 1. how can I know how...
6
8133
Cintury
by: Cintury | last post by:
Hi all, I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql...
0
7120
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
7160
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
7196
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
6878
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
7373
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...
0
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4583
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
286
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.