473,618 Members | 3,005 Online
Bytes | Software Development & Data Engineering Community
+ 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 1992
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 programmaticall y ok..
this.sqlConnect ion1.Connection String = "workstatio n id=HOST;packet
size=4096;integ rated security=SSPI;d ata source=HOST;per sist security
info=False;init ial catalog=Northwi nd";

this.sqlConnect ion1.Open();

System.Data.Sql Client.SqlComma nd cmd = new
System.Data.Sql Client.SqlComma nd("SELECT TOP 10 * FROM
Orders",sqlConn ection1);

System.Data.Sql Client.SqlDataR eader sr = cmd.ExecuteRead er();

if (sr.Read())

System.Windows. Forms.MessageBo x.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.ConnectionS tring =

"Data Source =(local);" +

"Initial Catalog=Northwi nd;" +

"Integrated Security=SSPI";
--
Br,
Mark Broadbent
mcdba , mcse+i
=============
"Alberto" <al*****@nospam .com> wrote in message
news:OZ******** ******@TK2MSFTN GP09.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 programmaticall y ok..
this.sqlConnect ion1.Connection String = "workstatio n id=HOST;packet
size=4096;integ rated security=SSPI;d ata source=HOST;per sist security
info=False;init ial catalog=Northwi nd";

this.sqlConnect ion1.Open();

System.Data.Sql Client.SqlComma nd cmd = new
System.Data.Sql Client.SqlComma nd("SELECT TOP 10 * FROM
Orders",sqlConn ection1);

System.Data.Sql Client.SqlDataR eader sr = cmd.ExecuteRead er();

if (sr.Read())

System.Windows. Forms.MessageBo x.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.ConnectionS tring =

"Data Source =(local);" +

"Initial Catalog=Northwi nd;" +

"Integrated Security=SSPI";
--
Br,
Mark Broadbent
mcdba , mcse+i
=============
"Alberto" <al*****@nospam .com> wrote in message
news:OZ******** ******@TK2MSFTN GP09.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******** *************** ***********@mic rosoft.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 programmaticall y ok..
this.sqlConnect ion1.Connection String = "workstatio n id=HOST;packet
size=4096;integ rated security=SSPI;d ata source=HOST;per sist security
info=False;init ial catalog=Northwi nd";

this.sqlConnect ion1.Open();

System.Data.Sql Client.SqlComma nd cmd = new
System.Data.Sql Client.SqlComma nd("SELECT TOP 10 * FROM
Orders",sqlConn ection1);

System.Data.Sql Client.SqlDataR eader sr = cmd.ExecuteRead er();

if (sr.Read())

System.Windows. Forms.MessageBo x.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.ConnectionS tring =

"Data Source =(local);" +

"Initial Catalog=Northwi nd;" +

"Integrated Security=SSPI";
--
Br,
Mark Broadbent
mcdba , mcse+i
=============
"Alberto" <al*****@nospam .com> wrote in message
news:OZ******** ******@TK2MSFTN GP09.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
3236
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 connection string' . When I write the string to the page using response.write(connectionstring) it shows up fine. Is the something else that I need to do? Thanks
11
2422
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 database through Connection.open() method, and I do not use Connection.close() method, will garbage collector collect the connection object just because i am not using it any more. 2) I am using a dataset, in which i make some modifications to the...
3
2475
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 removed the try/catch part as it is not important for my question: // This function opens a connection to the database. public static SqlConnection dbOpen() { // Create a SqlConnection object and pass in our connection string
7
2463
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 the database(Does not really matter but, in case you need to know, either MSSQL or ODBC ones) a few times when it loads to do the CURD things. How there's 3 ways proposed to do so:
3
10287
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 I use System.Data.Common.DBConnection and .DBCommand. How can I keep aware from connection losses (network not availeable, db-server not available...)? Are there any strategies to detect this broken connections, and how can I
35
4828
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 string in the web.config. I created a class with a static database connection and the class opens and closes the database.
6
3433
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 a database object to query data from database (using MySQL database). So it means that for each page request I am using 7 or 8 database connection which is something quite bad as far as performance is concerned. So please tell me how can change...
5
23996
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 development client. Bur Its gives me following error message. I searched lots of things on net and tried on remote server but i didnt got suceess. Can any one tell me how to set TCP\IP
20
3262
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 many connection has been used ? 2. If the maximum pool size has been reached, what happens when I call the method Open to open the connection ? Will I get an error ? MSDN says the request is queued, but will I get an error in the open method ? ...
6
8155
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 server mobile ce database. Until recently I was synching everything thru a com port serial cable. The devices would connect to the computer thru activesync and are able to acquire an internet connection. The sync for the program occurs thru a website...
0
8212
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8153
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8653
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8595
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7126
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6101
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1760
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1459
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.