Solved

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

Posted on 2004-08-18
10
2,297 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

623 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