Solved

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

Posted on 2004-08-18
10
2,287 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 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