473,399 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Component problem

nht
Hi, i have a problem. I try to create a non visual component. This is
a simple component that makes database connection. I use the following
code. But in design time i can't see the properties. I use public
properties. Everything seems ok but in design time i can not see the
properties that i have defined. I defined server name,database name,
user name and password as properties and all these should be given in
design time.

Here is the source code :

using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;
using System.Data.SqlClient;

namespace DBConnect
{
public class dbCon : System.ComponentModel.Component
{
private System.ComponentModel.Container components = null;
private string serverName;
private string dataBaseName;
private string userName;
private string passWord;
private bool conStatus;
private SqlConnection con;

public dbCon(System.ComponentModel.IContainer container)
{

container.Add(this);
InitializeComponent();

}

public dbCon()
{

InitializeComponent();

}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Component Designer generated code

private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion

[CategoryAttribute("Appearance"),BrowsableAttribute (true)]
public string ServerName
{
set
{
this.serverName=value;
}
}

[BrowsableAttribute(true)]
public string DataBase
{
set
{
this.dataBaseName=value;
}
}

[BrowsableAttribute(true)]
public string UserName
{
set
{
this.userName=value;
}
}

[BrowsableAttribute(true)]
public string PassWord
{
set
{
this.passWord=value;
}
}

[BrowsableAttribute(true)]
public bool isConnect
{
set
{
if(value)
{
if(openConnection())
this.conStatus=true;
}
else
{
if(closeConnection())
this.conStatus=false;
}
}
}

public SqlConnection Connection
{
get
{
return this.con;
}
}

private bool openConnection()
{
bool isException=false;
try
{
con=new SqlConnection();
con.ConnectionString="server="+serverName+";
database="+dataBaseName+"; uid="+userName+";pwd="+passWord;
con.Open();
}
catch(SqlException exp)
{
isException=true;
}
return isException;
}

private bool closeConnection()
{
if(con.State==System.Data.ConnectionState.Open)
{
try
{
con.Close();
con.Dispose();
}
catch(SqlException ex)
{
return false;
}
}
return true;
}
}
}
Nov 16 '05 #1
0 898

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: brazilnut52 | last post by:
I am going to outline the steps I go through to produce the problem. Hopefully this will help you understand the problem better I have created a simple COM DLL in .NET by using the COM class...
0
by: Doug | last post by:
Hello, We are having a problem with a component in our system that uses publisher policy files. Whenever it gets modified and moved out to where our build processes reference components for other...
1
by: Wolfgang Draxinger | last post by:
Component systems with C++ are quite some challenge. Microsoft tried it with COM and it was not the big hit, there is CORBA, which isn't focused on C++ but only supports a limited set of value...
1
by: Peter Rilling | last post by:
I created a COM+ component (ServicedComponent) in .NET. The component has a single method Connect() which returns a reference to a SqlConnection object. This component works fine when the world is...
2
by: brazilnut52 | last post by:
I am going to outline the steps I go through to produce the problem. Hopefully this will help you understand the problem better I have created a simple COM DLL in .NET by using the COM class...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.