none
Connecting Remote Instance of SQL Server using SMO RRS feed

  • Question

  •  

     Hi all,
    I need to know how to connect to a remote sql server using a C# window application. Let me make, my issue more clear. I want to develop a application in C#, that can connect to any SQL server whether its local or remote using valid crendentials. I saw many appliations, that search automatically into LAN for SQL Server instances. But I want user to put either server name or ip address instead of searching for insatnces automatically.
    Please help me out. if there is any online resource regarding this, please put it in reply
    Thanks and regards
    Amit Ranjan
    Saturday, June 7, 2008 6:14 AM

Answers

  • Please avoid concatenating connection strings.  This has a serious security flaw (connection string injection). 

     

    Use the SqlConnectionBuilder class instead, it does what you want without the security issues of concat.

     

    Tuesday, June 10, 2008 6:24 AM

All replies

  • You could customize the connection string for yourself. Here's a simple sample:

     

    using System.Data.SqlClient;

     

    string connectionString = string.Format("Server={0};Database={1};User id={2};Password={3}", server, database, username, password);

    SqlConnection conn = new SqlConnection(connectionString);

    conn.Open();

    .......

     

     

    For more information about SqlConnection, you could visit http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.aspx

     

     

    Saturday, June 7, 2008 7:40 AM
  • Please avoid concatenating connection strings.  This has a serious security flaw (connection string injection). 

     

    Use the SqlConnectionBuilder class instead, it does what you want without the security issues of concat.

     

    Tuesday, June 10, 2008 6:24 AM