Subject: I need help connecting to SQL Server 2000
Posted By: aehb Post Date: 3/11/2005 6:12:07 AM
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
Reply By: sumsin Reply Date: 3/11/2005 8:45:55 AM
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>


Reply By: aehb Reply Date: 3/11/2005 4:17:40 PM
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
Reply By: Alcapone Reply Date: 3/17/2005 9:42:07 AM
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=yourpassword;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.AppSettings["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
Reply By: stu9820 Reply Date: 3/17/2005 12:55:34 PM
Try http://www.connectionstrings.com/


Reply By: ejan Reply Date: 3/20/2005 10:26:43 AM
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=<password>


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
Reply By: aehb Reply Date: 4/27/2005 3:00:35 PM
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

Go to topic 29640

Return to index page 567
Return to index page 566
Return to index page 565
Return to index page 564
Return to index page 563
Return to index page 562
Return to index page 561
Return to index page 560
Return to index page 559
Return to index page 558