Jump to content
  • Advertisement
Sign in to follow this  
Lorand

C# Connecting to a Sql Server 2000

This topic is 2720 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Sup guys!
Ok so, first off happy new year! Now I have been trying to solve a problem of mine for quite a while now, but no matter how hard I try to solve it, it never works for me... I've checked many tutorials, but I still can't solve it.

What I'm doing:
I'm basically making a program similar to a messenger, but a bit different, where all the messages sent, are stored in a database on the computer we chose as the server... I've created a Database in SQL Server 2000 called DCCDataBase, and has a table called UserInfo right now(Just stores the users' name, password, priority, etc...). So in Enterprise Manager, I want to connect to: SQL Server Group\(local)(Windows NT)\Databases\DCCDataBase\Tables -> UserInfo
The Server Name is ROBERT.

Problem:
I'm creating this program on the server computer, and after many tries, I successfully can connect and modify that table, but when I try to connect from a different computer, I come across many problems... I successfully solved those too, but I can't pass this one: It keeps giving an error about Permissions...

Here is my code:


using System.Data.SqlClient;

namespace DCC
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
}

private void btn_Login_Click(object sender, EventArgs e)
{
SqlConnection sql_connection = new SqlConnection("server=ROBERT;uid=User;pwd=pass123;Data Source=localhost;Trusted_Connection=yes;Integrated Security=SSPI;Initial Catalog=DCCDataBase");

try
{
sql_connection.Open();
sql_connection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
sql_connection.Close();
Close();
}
Close();
}
}
}

- In the project settings: Security -> ClickOnce Security Settings is enabled with full trust.

Thanks for reading, hope anyone can help :)

Share this post


Link to post
Share on other sites
Advertisement
Check your connection string, you are using Integrated Security (Integrated Security=SSPI) . Meaning that there will be an attempt to login to the DB with the current user credentials.

Check: http://www.connectionstrings.com for a connectionstring specific to your situation.

Also, why do you use such an old SQL Server version?

Share this post


Link to post
Share on other sites

Check your connection string, you are using Integrated Security (Integrated Security=SSPI) . Meaning that there will be an attempt to login to the DB with the current user credentials.

Check: http://www.connectionstrings.com for a connectionstring specific to your situation.

Also, why do you use such an old SQL Server version?


Thank you very much Oxidda! That website really helps, but I am getting a new error which I've been trying to solve with no luck (changing my connection string in different ways)

On the computer I have the server on, I have no problem connecting to the server, but on the other computer it keeps having an exception of "Login failed for user 'ROBERT\Guest'.

I've tried creating new users on the server for that Database, for example "DCCLoginName"
Which was added to my connection string like this:

SqlConnection sql_connection = new SqlConnection("Server=ROBERT;User ID=DCCLoginName;Password=123456;Database=DCCDataBase;Trusted_Connection=true");

But I still get the same result. And if I simply try to change the Server in the String to lets say "ROBERT\\DCCLoginName" or "ROBERT\\dbo" I get a completely different error that states that it can't connect to the server.

Thanks for the help :)

P.S. I'm using SQL Server 2000 because I have no other version with me atm.

Share this post


Link to post
Share on other sites
I have successfully solved my problem! For anyone wanting to know the perfect connection string to an SQL Server 2000 database with C#, here is the code:

SqlConnection sql_connection = new SqlConnection("Data Source=xxxx.xxxx.xxxx.xxxx,1433;Network Library=DBMSSOCN;Initial Catalog=Database;User ID=sa;Password=;");

try
{
sql_connection.Open();
sql_connection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
sql_connection.Close();
Close();
}


I know its an older version, but it works :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!