Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-08-18
10
Medium Priority
?
2,301 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 1200 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 1200 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 300 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

Independent Software Vendors: 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!

Question has a verified solution.

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

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…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

704 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