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 March 11th, 2005, 07:12 AM
Authorized User
 
Join Date: Mar 2005
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to aehb
Default I need help connecting to SQL Server 2000

When trying to connect to the SQL Server 2000 using the statemnet:
"Trusted_Connection = yes" it's working, but

if trying to connect using a user name and password, it tells me that I don't use a trusted connection.

I need help to connect using a username and a password
 
Old March 11th, 2005, 09:45 AM
Authorized User
 
Join Date: Mar 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi
try it:
declare it in web.config file
<appSettings>
  <add key="connectionString" value="User=my_user; Password=my_pass; Persist Security True;Data Source=192.168.5.1\SQLINTERNAL" />
</appSettings>


 
Old March 11th, 2005, 05:17 PM
Authorized User
 
Join Date: Mar 2005
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to aehb
Default

Thanks a lot sumsin, but I want to use it in a windows application, not a web application, I hope you can help again, and thank you again very much
 
Old March 17th, 2005, 10:42 AM
Authorized User
 
Join Date: Aug 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Alcapone
Default

Hi aehb,

You should try the following:

in your project create a new file called App.config

insert this into the file,
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings>
        <add key="ConnectionString" value="server="yourservername";uid=youruser;pwd=yo urpassword;database=yourdatabase" />
    </appSettings>
</configuration>

in the form code add the following code:
public class Groups : System.Windows.Forms.Form
{
private string strconn = System.Configuration.ConfigurationSettings.AppSett ings["ConnectionString"].ToString();
//the rest of your code.
}
now you can use this strconn value anywhere in your from as your sqlconnection string...

like

sqlConnection conn = new Sqlconnection(strconn);

Hopefully this will help you...and it works not only in a webform but also in a windows form.

Regards,
alcapone
 
Old March 17th, 2005, 01:55 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Try http://www.connectionstrings.com/


 
Old March 20th, 2005, 11:26 AM
Authorized User
 
Join Date: May 2004
Posts: 83
Thanks: 0
Thanked 1 Time in 1 Post
Default

Dear aehb,

I'm sure that the solutions you've got so far must not have solved your problem coz they don't address the REAL issue you have.

Well, let's discuss connection strings first. We'll be discussing then the REAL problem.

If you're using a Windows account to login to SQL Server, your connection string should look like this:
Provider=SQLOLEDB;Data Source=<data_source_name>;
Initial Catalog=<database_name>;Integrated Security=SSPI


If you're using a SQL Server account to login to SQL Server, however, your connection string should resemble this one:
Provider=SQLOLEDB;Data Source=<data_source_name>;
Initial Catalog=<database_name>;uid=<user_id>;pwd=<passwor d>


Note: When using a SqlConnection object to connect to your database, plz remove Provider=SQLOLEDB; from your connection string.

Now let's discuss the REAL problem. Well, SQL Server can use two modes of security: Windows Authentication and Windows and SQL Server Authentication. In Windows Authentication only those users can login to SQL server who have a Windows account. Other users, including those having a valid SQL Server account, will simply be [b]not[b] allowed to login. In Windows and SQL Server Authentication, on the other hand, both types of users, those who have a Windows account and those who have a SQL Server account, can login to SQL server.

You might have guessed that the problem you're having is that your SQL server is configured to use Windows Authentication and you're trying to login to it using a SQL Server account! In order to be able to use either a Windows account or a SQL Server account to successfully login to your SQL server, you must configure it to use Windows and SQL Server Authentication. To do so, follow these steps:
  • Open SQL Server Enterprise Manager
  • Expand the nodes to show your SQL Server node
  • Right-click the SQL Server node and select Properties
  • On the Properties dialog box, click the Security tab
  • On the Security tab, under Authentication, select the SQL Server and Windows option button
  • Click the OK button
  • You'll be prompted to stop and restart the SQL Server service. Give a +ve response and wait until the service is restarted

Now your server will have been configured to use Windows and SQL Server Authentication mode and, so, you'll be able to login to it using either Windows or SQL Server account.

Hope you get your solution!

ejan
 
Old April 27th, 2005, 03:00 PM
Authorized User
 
Join Date: Mar 2005
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to aehb
Default

Thanks a lot for you all and for your advice, honestly I tried only the advice of "ejan" because it's the easiest to do, and it works. Thanks again "ejan" and thank you all :)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Connecting to SQL server 2000 with VB 2005 Express ericgelders Visual Basic 2005 Basics 0 February 20th, 2007 06:15 PM
Connecting WroxUnited DB's in SQL Server 2000 TritonOps ASP.NET 2.0 Basics 8 September 7th, 2006 11:29 PM
Connecting to SQL 2000 Belisarius C# 0 February 17th, 2006 04:07 PM
Error in connecting to sql server 2000 using asp method SQL Server 2000 1 March 7th, 2005 11:05 PM
I have problem connecting to SQL Server 2000 sp3 ctanchan SQL Server 2000 0 September 11th, 2003 07:35 PM





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