Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 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 August 31st, 2007, 06:03 PM
KW KW is offline
Registered User
 
Join Date: Feb 2007
Posts: 9
Thanks: 2
Thanked 1 Time in 1 Post
Default Problems connecting to SQL Server - correct post

Please ignore the first post for this topic. I accidently hit hte enter button.

I have tried to connect to a SQL Server db using code from the Professional C# 3rd edition book. None of the four things that I have tried from Ch 21 have been succesful. None of the other things that I have tried have been successful either.

I am using SQL Server 2005 Express Edition and Visual C# Express Edition as well.

I don't know is there is a problem with the code in the book or if there is something that I need to do. Please help.

...............Thanks
 
Old August 31st, 2007, 08:30 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Can you expand on what is not working? Are you getting error messages and, if so, what are they?

-Peter
 
Old September 1st, 2007, 09:25 AM
KW KW is offline
Registered User
 
Join Date: Feb 2007
Posts: 9
Thanks: 2
Thanked 1 Time in 1 Post
Default

   I am not getting any error messages from my code. I think the problem is that I haven't correctly specified my instance of SQL server in the connection string. I was going by an example in the book that used the generic

"Data Source=(local);Initial Catalog=master;Integrated" + "Security=SSPI";

   I seem to remember reading that it was okay to leave the
"Data Source=(local)". I thought that since I am developing for my
local machine that this would be okay for his situation. Evidently it isn't.

   I have talked to a friend that said that I need to specify the path to my instance of SQL Server. I think this is where things were going wrong. I am now trying to figure out how to do this.

   All of the stuff that I have found so far uses this generic
(local) example for the Data Source. I think that I should be doing something more like the following:

string strConnect = "Data Source=C:/Program Files/Microsoft SQL Server/MSSQL.1/MSSQL/Data; Initial Catalog=Northwind.mdf; Integrated Security=SSPI";

for the path specification and the connection string. Then later in the connection string I should then specify "Initial Catalog=Northwind.mdf" as the database that is going to be used.

Can you provide an example of a connection string that would correctly specify this info if the one that I have in this post is incorrect. I could then alter it for my situation.

Should I also be putting an @ sign in the path to specification. I remember reading about this but don't remember exactly what the purpose was. I think it was to denote something as being a literal.

Does the direction of the slashes in the path make a difference?be forward or back slashes?

Thanks for the help. My programmer friend has gone out of town for the next week. It will be great to get this working.




 
Old September 1st, 2007, 01:28 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

ConnectionStrings.com has examples of all kinds of connection string:

SQL Server
SQL Server 2005
SQL Server 2005 Compact Edition

Using a connection string for SQL Server with a file path in it is for SQL Server 2005 Express. This allows dynamic attaching to the MDF/LDF files.

"(local)" should be enough if you have a default local installation of the database. If you created a named instance then you can use "localhost\instancename".

-Peter
 
Old September 3rd, 2007, 11:53 AM
KW KW is offline
Registered User
 
Join Date: Feb 2007
Posts: 9
Thanks: 2
Thanked 1 Time in 1 Post
Default

thanks for the help.






Similar Threads
Thread Thread Starter Forum Replies Last Post
problems connecting to SQL Server KW C# 2005 0 August 31st, 2007 05:59 PM
Having problems connecting VB to SQL schow ASP.NET 2.0 Basics 0 March 28th, 2007 11:22 PM
URGENT:Connecting SQL server through Proxy server abhowal Pro VB Databases 2 January 9th, 2006 01:47 PM
Problems connecting SQL Server from VB 6 mikko SQL Server 2000 6 February 12th, 2004 05:37 AM
URGENT:Connecting SQL server through Proxy server sankar SQL Server 2000 0 August 26th, 2003 03:50 AM





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