Click here to Skip to main content
15,915,864 members
Home / Discussions / C#
   

C#

 
QuestionOne database Connection [modified] Pin
Shivendra Pandey21-Dec-09 23:41
Shivendra Pandey21-Dec-09 23:41 
AnswerRe: One database Connection Pin
Saksida Bojan21-Dec-09 23:49
Saksida Bojan21-Dec-09 23:49 
AnswerRe: One database Connection Pin
Ashfield22-Dec-09 0:26
Ashfield22-Dec-09 0:26 
AnswerRe: One database Connection Pin
Paulo Zemek22-Dec-09 1:53
Paulo Zemek22-Dec-09 1:53 
AnswerRe: One database Connection Pin
hosseinghazanfary22-Dec-09 7:38
hosseinghazanfary22-Dec-09 7:38 
QuestionDatagridviewcomboboxcell value is not valid Pin
kvsrikanth21-Dec-09 23:22
kvsrikanth21-Dec-09 23:22 
AnswerRe: Datagridviewcomboboxcell value is not valid Pin
Blue_Boy21-Dec-09 23:31
Blue_Boy21-Dec-09 23:31 
Questionissue with Date Format in SSRS Pin
siddisagar21-Dec-09 22:49
siddisagar21-Dec-09 22:49 
AnswerRe: issue with Date Format in SSRS Pin
Saksida Bojan21-Dec-09 23:23
Saksida Bojan21-Dec-09 23:23 
GeneralRe: issue with Date Format in SSRS Pin
Blue_Boy21-Dec-09 23:33
Blue_Boy21-Dec-09 23:33 
GeneralRe: issue with Date Format in SSRS Pin
Saksida Bojan21-Dec-09 23:39
Saksida Bojan21-Dec-09 23:39 
GeneralRe: issue with Date Format in SSRS Pin
Blue_Boy21-Dec-09 23:54
Blue_Boy21-Dec-09 23:54 
QuestionC# Data link to another PC? Pin
miss YY21-Dec-09 22:20
miss YY21-Dec-09 22:20 
AnswerRe: C# Data link to another PC? Pin
Calla21-Dec-09 22:30
Calla21-Dec-09 22:30 
AnswerRe: C# Data link to another PC? Pin
The Man from U.N.C.L.E.21-Dec-09 22:38
The Man from U.N.C.L.E.21-Dec-09 22:38 
AnswerRe: C# Data link to another PC? Pin
rag_Singh21-Dec-09 22:57
rag_Singh21-Dec-09 22:57 
AnswerRe: C# Data link to another PC? Pin
Md. Marufuzzaman22-Dec-09 10:36
professionalMd. Marufuzzaman22-Dec-09 10:36 
AnswerRe: C# Data link to another PC? [modified] Pin
hamed-vojdani24-Dec-09 7:13
hamed-vojdani24-Dec-09 7:13 
My offer ,else use MSDASC class


now see what is my offer..

1- Server side:
Run Sql Server browser Service in your database server machine, then
create Valid login for your database,set sql server authentication to Windows and SQL athentication
2- Application side:
with a form like this:
http://privateimage.com/images/9fq89vuk7uokjz8koz.jpg

and with functions like below for buttons
private void btnSearch_Click(object sender, EventArgs e)
{
    SqlDataSourceEnumerator SqlEnumerator = SqlDataSourceEnumerator.Instance;
    DataTable dt = new DataTable();
    dt = SqlEnumerator.GetDataSources();
    dataGridView1.DataSource = dt.DefaultView;
}


private void btnSave_Click(object sender, EventArgs e)
{
    if (dataGridView1.SelectedRows.Count != 0)
    {
        string ConString = "";

        SqlConnectionStringBuilder builder =new SqlConnectionStringBuilder();
        builder.ApplicationName = "MyApp";
        builder.WorkstationID = Environment.MachineName;
        builder.UserID = txtLoginName.Text.Trim();
        builder.Password = txtPassword.Text.Trim());
        builder.InitialCatalog="MyDBName";
        builder.DataSource = dataGridView1.SelectedRows[0].Cells["ServerName"].Value.ToString()+
       "\\"+dataGridView1.SelectedRows[0].Cells["InstanceName"].Value.ToString();

        ConString = builder.ConnectionString;

    }

}


at the end your data link string is ConString variable, you can store it in encrypted file or registry. each time application start check stored connection, and if failed retry this form

note: used namespace are:
using System.Data.Sql;
using System.Data.SqlClient;

hope helps with ugly sample Wink | ;)

modified on Friday, December 25, 2009 9:45 AM

QuestionBeginner Question: Data Binding Controls in C# WinForms Pin
Jyncus21-Dec-09 21:50
Jyncus21-Dec-09 21:50 
QuestionSSRS Date format help required Pin
siddisagar21-Dec-09 18:03
siddisagar21-Dec-09 18:03 
AnswerRe: SSRS Date format help required Pin
Saksida Bojan21-Dec-09 19:29
Saksida Bojan21-Dec-09 19:29 
QuestionSqlite + TEXT Pin
Ryan Minor21-Dec-09 11:06
Ryan Minor21-Dec-09 11:06 
AnswerRe: Sqlite + TEXT Pin
S. Brozius21-Dec-09 11:40
S. Brozius21-Dec-09 11:40 
QuestionScroll bar apperance Pin
viciouskinid21-Dec-09 10:58
viciouskinid21-Dec-09 10:58 
AnswerRe: Scroll bar apperance Pin
Luc Pattyn21-Dec-09 11:27
sitebuilderLuc Pattyn21-Dec-09 11:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.