Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2303
  • Last Modified:

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

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
fallenarmies
Asked:
fallenarmies
  • 3
  • 3
  • 2
  • +2
3 Solutions
 
mmarinovCommented:
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
 
fallenarmiesAuthor Commented:
Cheers

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

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

Regards,
B..M
0
Technology Partners: 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!

 
tovvenkiCommented:
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
 
thefallguyCommented:
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
 
fallenarmiesAuthor Commented:
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
 
daffodilsCommented:
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
 
daffodilsCommented:
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
 
fallenarmiesAuthor Commented:
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
 
daffodilsCommented:
sure...
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now