473,385 Members | 1,647 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,385 software developers and data experts.

Connection to SQL

What is the best way to connect to a SQL database from ASP.NET?

Thanks,

--
David Lozzi
Web Applications/Network Specialist
Delphi Technology Solutions, Inc.
dlozzi(remove-this)@delphi-ts.com

Nov 18 '05 #1
8 2789
System.Data.SqlClient NameSpace.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"David Lozzi" <dlozzi(remove-this)@delphi-ts.com> wrote in message
news:uZ*************@TK2MSFTNGP12.phx.gbl...
What is the best way to connect to a SQL database from ASP.NET?

Thanks,

--
David Lozzi
Web Applications/Network Specialist
Delphi Technology Solutions, Inc.
dlozzi(remove-this)@delphi-ts.com

Nov 18 '05 #2
//This code inserts, updates or deletes a record(s) in a table using a
stored procedure with a single parameter.
//It would need to be modified for a Select statement that retrieved
records.

SqlConnection sqlConn = new SqlConnection("your connection string goes
here");
sqlConn.Open();
SqlCommand sqlComm = new SqlCommand("Your_stored_procedure_name", sqlConn);
SqlParameter prm1 = new SqlParameter("@my_prm",varchar,10);
prm1.value = "neat";
sqlComm.Parameters.Add(prm1);
sqlComm.CommandType = CommandType.StoredProcedure;
Int32 intNumberOfRecordsAffected = sqlComm.ExecuteNonQuery();
sqlConn.Close();

Hope this helps.

Mark
www.dovetaildatabases.com

"David Lozzi" <dlozzi(remove-this)@delphi-ts.com> wrote in message
news:uZ*************@TK2MSFTNGP12.phx.gbl...
What is the best way to connect to a SQL database from ASP.NET?

Thanks,

--
David Lozzi
Web Applications/Network Specialist
Delphi Technology Solutions, Inc.
dlozzi(remove-this)@delphi-ts.com

Nov 18 '05 #3
Could I have a little more information? Like an example or a MS reference?

--
David Lozzi
Web Applications/Network Specialist
Delphi Technology Solutions, Inc.
dlozzi(remove-this)@delphi-ts.com
"Kevin Spencer" <ks******@takempis.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
System.Data.SqlClient NameSpace.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"David Lozzi" <dlozzi(remove-this)@delphi-ts.com> wrote in message
news:uZ*************@TK2MSFTNGP12.phx.gbl...
What is the best way to connect to a SQL database from ASP.NET?

Thanks,

--
David Lozzi
Web Applications/Network Specialist
Delphi Technology Solutions, Inc.
dlozzi(remove-this)@delphi-ts.com


Nov 18 '05 #4
I get an error: Type 'SqlConnection' is not defined.

--
David Lozzi
Web Applications/Network Specialist
Delphi Technology Solutions, Inc.
dlozzi(remove-this)@delphi-ts.com
"Mark" <mf****@idonotlikespam.cce.umn.edu> wrote in message
news:uA**************@tk2msftngp13.phx.gbl...
//This code inserts, updates or deletes a record(s) in a table using a
stored procedure with a single parameter.
//It would need to be modified for a Select statement that retrieved
records.

SqlConnection sqlConn = new SqlConnection("your connection string goes
here");
sqlConn.Open();
SqlCommand sqlComm = new SqlCommand("Your_stored_procedure_name", sqlConn); SqlParameter prm1 = new SqlParameter("@my_prm",varchar,10);
prm1.value = "neat";
sqlComm.Parameters.Add(prm1);
sqlComm.CommandType = CommandType.StoredProcedure;
Int32 intNumberOfRecordsAffected = sqlComm.ExecuteNonQuery();
sqlConn.Close();

Hope this helps.

Mark
www.dovetaildatabases.com

"David Lozzi" <dlozzi(remove-this)@delphi-ts.com> wrote in message
news:uZ*************@TK2MSFTNGP12.phx.gbl...
What is the best way to connect to a SQL database from ASP.NET?

Thanks,

--
David Lozzi
Web Applications/Network Specialist
Delphi Technology Solutions, Inc.
dlozzi(remove-this)@delphi-ts.com


Nov 18 '05 #5
If i put System.Data.SqlClient. infront of it, it works fine. How can I
'declare' this for the entire doc?

--
David Lozzi
Web Applications/Network Specialist
Delphi Technology Solutions, Inc.
dlozzi(remove-this)@delphi-ts.com
"David Lozzi" <dlozzi(remove-this)@delphi-ts.com> wrote in message
news:O8*************@tk2msftngp13.phx.gbl...
I get an error: Type 'SqlConnection' is not defined.

--
David Lozzi
Web Applications/Network Specialist
Delphi Technology Solutions, Inc.
dlozzi(remove-this)@delphi-ts.com
"Mark" <mf****@idonotlikespam.cce.umn.edu> wrote in message
news:uA**************@tk2msftngp13.phx.gbl...
//This code inserts, updates or deletes a record(s) in a table using a
stored procedure with a single parameter.
//It would need to be modified for a Select statement that retrieved
records.

SqlConnection sqlConn = new SqlConnection("your connection string goes
here");
sqlConn.Open();
SqlCommand sqlComm = new SqlCommand("Your_stored_procedure_name",

sqlConn);
SqlParameter prm1 = new SqlParameter("@my_prm",varchar,10);
prm1.value = "neat";
sqlComm.Parameters.Add(prm1);
sqlComm.CommandType = CommandType.StoredProcedure;
Int32 intNumberOfRecordsAffected = sqlComm.ExecuteNonQuery();
sqlConn.Close();

Hope this helps.

Mark
www.dovetaildatabases.com

"David Lozzi" <dlozzi(remove-this)@delphi-ts.com> wrote in message
news:uZ*************@TK2MSFTNGP12.phx.gbl...
What is the best way to connect to a SQL database from ASP.NET?

Thanks,

--
David Lozzi
Web Applications/Network Specialist
Delphi Technology Solutions, Inc.
dlozzi(remove-this)@delphi-ts.com



Nov 18 '05 #6
Assuming we're talking C# here, you can include the following line at the
top of your code-behind:

using System.Data;
using System.Data.SqlClient;

mark
www.dovetaildatabases.com
"David Lozzi" <dlozzi(remove-this)@delphi-ts.com> wrote in message
news:uW**************@tk2msftngp13.phx.gbl...
If i put System.Data.SqlClient. infront of it, it works fine. How can I
'declare' this for the entire doc?

--
David Lozzi
Web Applications/Network Specialist
Delphi Technology Solutions, Inc.
dlozzi(remove-this)@delphi-ts.com
"David Lozzi" <dlozzi(remove-this)@delphi-ts.com> wrote in message
news:O8*************@tk2msftngp13.phx.gbl...
I get an error: Type 'SqlConnection' is not defined.

--
David Lozzi
Web Applications/Network Specialist
Delphi Technology Solutions, Inc.
dlozzi(remove-this)@delphi-ts.com
"Mark" <mf****@idonotlikespam.cce.umn.edu> wrote in message
news:uA**************@tk2msftngp13.phx.gbl...
//This code inserts, updates or deletes a record(s) in a table using a
stored procedure with a single parameter.
//It would need to be modified for a Select statement that retrieved
records.

SqlConnection sqlConn = new SqlConnection("your connection string goes
here");
sqlConn.Open();
SqlCommand sqlComm = new SqlCommand("Your_stored_procedure_name",

sqlConn);
SqlParameter prm1 = new SqlParameter("@my_prm",varchar,10);
prm1.value = "neat";
sqlComm.Parameters.Add(prm1);
sqlComm.CommandType = CommandType.StoredProcedure;
Int32 intNumberOfRecordsAffected = sqlComm.ExecuteNonQuery();
sqlConn.Close();

Hope this helps.

Mark
www.dovetaildatabases.com

"David Lozzi" <dlozzi(remove-this)@delphi-ts.com> wrote in message
news:uZ*************@TK2MSFTNGP12.phx.gbl...
> What is the best way to connect to a SQL database from ASP.NET?
>
> Thanks,
>
> --
> David Lozzi
> Web Applications/Network Specialist
> Delphi Technology Solutions, Inc.
> dlozzi(remove-this)@delphi-ts.com
>
>
>



Nov 18 '05 #7
Here is a link to the freely-downloadable and complete Microsoft .Net SDK,
which has plenty of references, articles, tutorials, and samples:

http://www.microsoft.com/downloads/d...displaylang=en

That's the best I can give you without a more detailed request.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"David Lozzi" <dlozzi(remove-this)@delphi-ts.com> wrote in message
news:eP**************@tk2msftngp13.phx.gbl...
Could I have a little more information? Like an example or a MS reference?

--
David Lozzi
Web Applications/Network Specialist
Delphi Technology Solutions, Inc.
dlozzi(remove-this)@delphi-ts.com
"Kevin Spencer" <ks******@takempis.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
System.Data.SqlClient NameSpace.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"David Lozzi" <dlozzi(remove-this)@delphi-ts.com> wrote in message
news:uZ*************@TK2MSFTNGP12.phx.gbl...
What is the best way to connect to a SQL database from ASP.NET?

Thanks,

--
David Lozzi
Web Applications/Network Specialist
Delphi Technology Solutions, Inc.
dlozzi(remove-this)@delphi-ts.com



Nov 18 '05 #8
OK, i think i found the solutions..

thanks,

--
David Lozzi
Web Applications/Network Specialist
Delphi Technology Solutions, Inc.
dlozzi(remove-this)@delphi-ts.com
"David Lozzi" <dlozzi(remove-this)@delphi-ts.com> wrote in message
news:uZ*************@TK2MSFTNGP12.phx.gbl...
What is the best way to connect to a SQL database from ASP.NET?

Thanks,

--
David Lozzi
Web Applications/Network Specialist
Delphi Technology Solutions, Inc.
dlozzi(remove-this)@delphi-ts.com

Nov 18 '05 #9

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

Similar topics

3
by: G-Fit | last post by:
Hello group, I have several servers hosting SQL databases. On each of them, I have several databases. All those databases have the same structure (even those on different servers), only the data...
11
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...
6
by: Chris Szabo | last post by:
I've created a data access layer for a .NET web application. I'm using C# and framework 1.1. I'm getting an error from time to time when I close a connection saying: ...
18
by: Rob Nicholson | last post by:
We're getting an occasional occurrence of the following error when two users try and open the same record in our ASP.NET app: "There is already an open DataReader associated with this Connection...
35
by: Eric Sabine | last post by:
In my Finally block, I was using cn.close (where cn is an ADO.NET connection object, SQLConnection to be exact) and then I came across the following in some microsoft code. If Not cn Is Nothing...
3
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...
20
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...
3
by: fniles | last post by:
In the Windows application (using VB.NET 2005) I use connection pooling like the following: In the main form load I open a connection using a connection string that I stored in a global variable...
0
by: Robert Avery | last post by:
In VBA/VB6, I had a class (incomplete sample below) that watched and displayed for the user all connection events, so that I could easily see what SQL was taking a long time, and when it freezes, I...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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.