Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 19th, 2008, 04:47 PM
Authorized User
 
Join Date: Feb 2008
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??

 
Old February 19th, 2008, 05:03 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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?





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 06:15 PM
SQL Server 2005 Express Edition vs. Released maitthm SQL Server 2005 3 March 31st, 2006 11:40 AM
Connecting to SQL Server Express venkikrao VB.NET 3 February 4th, 2006 12:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.