473,607 Members | 2,659 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem connecting to sql server on network?

38 New Member
Hi, Everyone

I am trying to connect to an SQL 2000 server in c# using a windows application. What I'm trying to do is ask the user to type in the server name and from the user's input take that server name that they enter in and connect to that server. i also want them to enter a user name and password (SQL authentication) and hide their connection string. Here is my code:

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Data.Sql;
  9. using System.Data.SqlClient;
  10. using System.Data.SqlTypes;
  11.  
  12. namespace WindowsApplication4
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         public Form1()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.         private void button1_Click(object sender, EventArgs e)
  22.         {
  23.             SqlConnection connection = new SqlConnection();
  24.             connection.ConnectionString = "Server=" + textBox1.Text + ";User ID=;PWD=;database=";
  25.             connection.Open();
  26.             SqlCommand thisCommand = connection.CreateCommand();
  27.  
  28.             textBox1.Text = "Connected";
  29.  
  30.             //create dataset to hold rows, columns, etc
  31.             DataSet dataset = new DataSet();
  32.  
  33.             connection.Close();
  34.         }
  35.         private void get_tables()
  36.         {
  37.  
  38.           //     DataTable tables = new DataTable("Tables");
  39.            //     using (SqlConnection connection =
  40.        //new SqlConnection(connectionString))
  41.  
  42.    //SqlCommand command = connection.CreateCommand();
  43.     //command.CommandText = "select table_name as Name from
  44.     //          INFORMATION_SCHEMA.Tables where TABLE_TYPE =
  45.        //       'BASE TABLE'";
  46.   //  connection.Open();
  47.   //  tables.Load(command.ExecuteReader(
  48.        //             CommandBehavior.CloseConnection));
  49. }
  50.     }
  51. }
  52.  
Can some please help me, I don't understand why I can't connect to the sql server when the user provides the server information?

Thanks
Jul 6 '07 #1
10 1530
Clanguage
12 New Member
I see that you enter the Server name via the texbox but I do not see any UserID or PWD being passed to the connection string
Expand|Select|Wrap|Line Numbers
  1. connection.ConnectionString = "Server=" + textBox1.Text + ";User ID=;PWD=;database=";
Jul 6 '07 #2
lildiapaz
38 New Member
I see that you enter the Server name via the texbox but I do not see any UserID or PWD being passed to the connection string
Expand|Select|Wrap|Line Numbers
  1. connection.ConnectionString = "Server=" + textBox1.Text + ";User ID=;PWD=;database=";
I want to prompt the user to enter their user name and password. i included this in the connection string "User ID=login; Password=passwo rd" and it still didn't work

Am I doing something wrong?
Jul 9 '07 #3
ahmadmsc
4 New Member
put textBox1.Text = "Connected" ; before connection string
Jul 10 '07 #4
ahmadmsc
4 New Member
NOT Necessary to give user name and PW if he already logged in as admin or SA
Jul 10 '07 #5
lildiapaz
38 New Member
NOT Necessary to give user name and PW if he already logged in as admin or SA
What do you mean? I don't want the user to login under sa or admin. How do I get around this issue and prompt them for user name and password while still using sql authentication?

I'm still confused
Jul 10 '07 #6
Clanguage
12 New Member
I want to prompt the user to enter their user name and password. i included this in the connection string "User ID=login; Password=passwo rd" and it still didn't work

Am I doing something wrong?
Hello lildiapaz,
I was never notified that I had an answer waiting for my reply to you. I will have to check the board settings so that I get a warning when someone replies.
Can you clarify your situation?
Are you saying that when you hardcode the username and the password you do not get a connection. Like
connection.Conn ectionString = "Server=" + textBox1.Text + ";User
Expand|Select|Wrap|Line Numbers
  1. ID=MyUserID;PWD=MyPassword;database=MyDatabase"; 
If you want to make it interactive you need something like
Expand|Select|Wrap|Line Numbers
  1. connection.ConnectionString = "Data Source=" + textBox1.Text + ";User ID=;" + txtUserID.text + "PWD=" + txtPassword.text + ";database=" = + txtDatabase.text + ""; "
Jul 10 '07 #7
lildiapaz
38 New Member
Hello lildiapaz,
I was never notified that I had an answer waiting for my reply to you. I will have to check the board settings so that I get a warning when someone replies.
Can you clarify your situation?
Are you saying that when you hardcode the username and the password you do not get a connection. Like
connection.Conn ectionString = "Server=" + textBox1.Text + ";User
Expand|Select|Wrap|Line Numbers
  1. ID=MyUserID;PWD=MyPassword;database=MyDatabase"; 
If you want to make it interactive you need something like
Expand|Select|Wrap|Line Numbers
  1. connection.ConnectionString = "Data Source=" + textBox1.Text + ";User ID=;" + txtUserID.text + "PWD=" + txtPassword.text + ";database=" = + txtDatabase.text + ""; "
It's ok, thanks for the response. My situation is that i want to make my windows c# application as interactive as possible. like I mentioned above the problem that I am having is when I specify a server on the network, it does not connect to anything. I placed the code in a try an catch to see what it was doing and it never connects to the server nor does it prompt me for a user name or password.

Do you think there could be something wrong with my sql 2000 settings that is not allowing me to connect to server/database?

Can anyone help?
Jul 10 '07 #8
Clanguage
12 New Member
Once again I was not notified of your reply.

The server will not prompt you. You need to build the string yourself. Create 4 textboxes and populate them with your server name, Database Name, User Name and password. You should see the result like the string I included at the foot of this post. this should take care of your connection string.
Expand|Select|Wrap|Line Numbers
  1.         Dim m_connectionString As String
  2.         If m_connectionString Is Nothing Then
  3.             m_connectionString = "Data Source=" + txtServerName.text + ";"
  4.             m_connectionString += "Initial Catalog=" + txtDbName.text + ";"
  5.             m_connectionString += "User ID=" + txtUserID.text + ";"
  6.             m_connectionString += "Password=" + txtPassword.text + ";"
  7.         End If
  8.  
"Data Source=localHos t;Initial Catalog=Northwi nd;UserID=clang uage;Password=e nter;"
Jul 11 '07 #9
prpleprncs
5 New Member
Are they logging onto a domain. If so, you can add all the users in the OU to SQL and allow the users to log in using Windows Authentication.

Even if you use the textboxes with SQL Authentication, you are still going to have to manage the users within SQL.

Have to created the users and given them access to the database?
Jul 12 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

12
2765
by: Ann Marinas | last post by:
Hi all, I would like to ask for some help regarding separating the asp.net webserver and the sql server. I have created an asp.net application for a certain company. Initially, we installed both the iis and sql server in a single machine. Not too long ago, the machine had some hardware problems, and management has decided to purchase new servers, for both asp.net and sql server.
2
3546
by: John | last post by:
Hi I was working fine with create user wizard and the default membership provider. I have now customised the membership provider as per attached web.config. The create user wizard picks up the custom membership provider fine and removes the security question/answer fields as designated in the custom provider. The problem is that when I try to create a new user in the create user wizard by entering the info and pressing the 'create...
0
5381
by: mortenol | last post by:
Hi, I am trying to connect a MS SSIS package to an AS400/DB2 database, and I experience problem when I hit the "Create Package" button in the "Data Link properties window". I have understood that the packages need to be created, before I can run any SQL on the DB2 base via SSIS(?). Here are the steps that I have done before the problem arise: 1. In MS Visual Studios, I created a new project of type "Integration Services". 2. On the...
0
3912
by: Suresh | last post by:
Hi Guys I have Db2 server installed on remote server. i am connecting to that remote server by using VPN. I want to connect that remote DB2 server instance using my local machine DB2 development client. Bur Its gives me following error message. I searched lots of things on net and tried on remote server but i didnt got suceess. Can any one tell me how to set TCP\IP connection protocol on server for particular instance. Becuase I think
5
23993
by: Suresh | last post by:
Hi Guys I have Db2 server installed on remote server. i am connecting to that remote server by using VPN. I want to connect that remote DB2 server instance using my local machine DB2 development client. Bur Its gives me following error message. I searched lots of things on net and tried on remote server but i didnt got suceess. Can any one tell me how to set TCP\IP
0
2857
by: NoaGross | last post by:
Hi, I'm relly new in java and I have a problem. I'm using java applet. When using http all ok, but when trying to use https i get: Java Plug-in 1.5.0_10 Using JRE version 1.5.0_10 Java HotSpot(TM) Client VM User home directory = C:\Documents and Settings\noa ---------------------------------------------------- c: clear console window
1
12532
by: Vikram S | last post by:
Hi All, I have an ASP.NET 2.0 web application on a web server and a separate machine for SQL Server 2000 Database. I am using a Connectionstring based on Sql Authentication to connect to the the SQL 2000 Database. Now, When I open the web page on the Web Server itself, I am able to successfully connect to the Database which confirms that the connection string is correct. However when I open the same web page from another client
8
2165
by: JDavis | last post by:
I am using System.Net.Sockets to connect a client socket to a server that requires three inputs when I connect: host, port and an identification number that identifies the person connecting. None of the overloads for either the Connect or BeginConnect methods takes that many inputs (basically they take host and port only). Would it be best to create a new class that derives from the base class System.Net.Sockets and implement a new...
2
3032
by: orandov | last post by:
Hi, I am having a problem connecting my .net applications from the application server to the database server. When I run the application from my windows xp (sp2) box it works fine. When I try to connect via SQL Management Studio to the database server from the application server I get the same error. Here is the error:
0
1991
by: aboutjav.com | last post by:
Hi, I need some help. I am getting this error after I complete the asp.net register control and click on the continue button. It crashed when it tries to get it calls this Profile property ((string)(this.GetPropertyValue("Address1")));
0
8049
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8128
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8322
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5997
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5471
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3953
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4013
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2461
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1574
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.