Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 19th, 2008, 03:47 PM
Authorized User
 
Join Date: Feb 2008
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Connecting SQL server express edition

I am using sql server express edition, that comes along with visual studio 2005, in my application. i made the database by adding a new database in application data. i gave the following code for connecting :

SqlConnection cn=new SqlConnection();
        cn.ConnectionString = "data source=Gaurav;Database=tracker";
        cn.Open();
        string sql = "Insert into track (node_id,node_name,node_no) values ('fffff','fffff',45)";
        SqlCommand cmd = new SqlCommand(sql, cn);
        cmd.ExecuteScalar();
        cn.Close();

here, gaurav is my server name and tracker is the database. on debugging, it displays the error message as "unable to connect to the database, and that it does not allow remote login. can anybody help??

Reply With Quote
  #2 (permalink)  
Old February 19th, 2008, 04:03 PM
Imar's Avatar
Wrox Author
Points: 71,632, Level: 100
Points: 71,632, Level: 100 Points: 71,632, Level: 100 Points: 71,632, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,014
Thanks: 79
Thanked 1,577 Times in 1,554 Posts
Default

Hi there,

You need to provide much more information. How is the instance of SQL Server called? Did you install it as a SqlExpress instance? If so, did you try Gaurav\SqlExpress

Also, take a look at other SqlExpress connection strings If by "new database in application data" you are referring to the App_Data folder, you need a different connection string that uses the AttachDBFileName attribute.

Take a look at the following URLs for a better understanding of SQL Server security and connection strings:

http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=395
http://www.connectionstrings.com

P.S. Hopefully this code snippet is just an example. Usually it's considered a bad practice to embed connection strings in your code directly. For some better ideas: http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=250

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
While typing this post, I was listening to: Without Belief by Nitzer Ebb (Track 9 from the album: Belief) What's This?
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Server 2005 Express Edition: Error message jsbotts713 SQL Server 2005 1 September 26th, 2007 02:03 PM
Connecting to SQL Server 2005 Express Locally GM_Access BOOK: Beginning Access 2003 VBA 1 August 7th, 2007 06:34 PM
Connecting to SQL server 2000 with VB 2005 Express ericgelders Visual Basic 2005 Basics 0 February 20th, 2007 05:15 PM
SQL Server 2005 Express Edition vs. Released maitthm SQL Server 2005 3 March 31st, 2006 10:40 AM
Connecting to SQL Server Express venkikrao VB.NET 3 February 3rd, 2006 11:00 PM



All times are GMT -4. The time now is 09:31 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.