Solved

Best way to connect to SQL Server using ASP.NET with C#

Posted on 2004-08-18
10
2,282 Views
Last Modified: 2008-01-09
Just a quick question

What is the recommeneded way of connecting to a SQL server database, and what are some good tutorials/ other questions using this method.
0
Comment
Question by:fallenarmies
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 28

Assisted Solution

by:mmarinov
mmarinov earned 400 total points
ID: 11828146
Hi,

all depends on the security level you want to use. the easier to maitain and the wide use is to store the connection string in the web config file and use trusted connection. for this you can look here : http://www.connectionstrings.com/

Regards,
B..M
0
 

Author Comment

by:fallenarmies
ID: 11828158
Cheers

But which is best SQL Connect or OLEDB Connection, provided the site needs a medium level of security.
0
 
LVL 28

Accepted Solution

by:
mmarinov earned 400 total points
ID: 11828174

for this question take a look at this discussion : http://www.csharpfriends.com/Forums/ShowPost.aspx?PostID=24347

Regards,
B..M
0
 
LVL 21

Expert Comment

by:tovvenki
ID: 11828272
Hi,
check whether the discussion at http://www.dotnet247.com/247reference/msgs/32/161150.aspx helps you
When connecting to sql server I always prefer SqlClient because it was optimise to perform well with Sql Servers

regards,
venki
0
 
LVL 1

Assisted Solution

by:thefallguy
thefallguy earned 100 total points
ID: 11831588
I prefer SqlClient class also. However, to design a robust Data Access Layer, I recommend reading this link

http://www.15seconds.com/issue/020611.htm
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:fallenarmies
ID: 11832022
Ok cheers for all the links, I think Im getting there.

Im having a rather simple problem with my SQL String

cmd.CommandText = "Insert INTO Journal (UserID,JournalTitle,CountryID,CityID,DateEntry,JournalDate,JournalEntry,Private) VALUES ("UserName","JournalTitle","Country","City","Date",'09022004',"Comments",'1')";

cmd.ExecuteScalar();

Basically this line is complaining, I was hoping to take entries from Textboxes and put them in directly, (Bearing in my I dont know the date fuction so Im hardcoding that in, and Im hardcoding in a boolean) If I hardcode in all the details then it works just fine, but when I try to do it this way it kicks up a fuss. :(

Any ideas? The error says its expecting a ;

But I think its to do with how I have the Variables in.
0
 
LVL 8

Expert Comment

by:daffodils
ID: 11834557
Use single quotes for values to be inserted.

cmd.CommandText = "Insert INTO Journal (UserID,JournalTitle,CountryID,CityID,DateEntry,JournalDate,JournalEntry,Private) VALUES ('UserName','JournalTitle','Country','City','Date','09022004','Comments','1')";
0
 
LVL 8

Expert Comment

by:daffodils
ID: 11842123
Hey fallenarmies ..
I know that I had not answered the main question, rather a follow-up question..
But did my answer not help ? Or had you already solved the error on your own?

0
 

Author Comment

by:fallenarmies
ID: 11842203
Sorry mate but when I used your query it didnt work, I had something similar to that but it didnt work

My solution was

Insert INTO Journal (UserID,JournalTitle,CountryID,CityID,DateEntry,JournalDate,JournalEntry,Private) VALUES ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','1')", UserName.Text,JournalTitle.Text,Country.Text,City.Text,MyDateTime,Date.Text,Comments.Text)

Which I found through links on some of the above pages.
0
 
LVL 8

Expert Comment

by:daffodils
ID: 11842604
sure...
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now