1

If i have a dll which i use in many web applications to use methods in this dll in my applications.

What 's the best practice to handle the connection string ?

The dll methods are static methods ..

this is what i do

 private static String connectionString = "User Id=xxx;Password=xxx;Host=xxx;Server=xxx;Service=1525;Database=xxx; Client Locale=ar_ae.1256; Database Locale=ar_ae.8859-6; Protocol=olsoctcp;pooling=true;Min Pool Size=4;Max Pool Size=400;Connection Timeout=30";

public static int Is_Valid_User(string p_u, string p_p)
        {
            int ret = 0;  // invalid user
            using (IfxConnection conn = new IfxConnection(connectionString))
            {
                IfxCommand DBCmd = new IfxCommand();
                String p = My_Decryption_2(p_p);
                try
                {
                    if (conn.State == ConnectionState.Closed)
                        conn.Open();
                    DBCmd = new IfxCommand();
                    DBCmd.Connection = conn;
                    DBCmd.CommandText = "SELECT nvl(emp_num,0) FROM emp_net WHERE username = ? AND DECRYPT_CHAR(password, 'xxxxxx') = ? ";
                    DBCmd.Parameters.Add("user_name", p_u);
                    DBCmd.Parameters.Add("password", p);
                    using (IfxDataReader dataReader = DBCmd.ExecuteReader())
                    {
                        if (dataReader.Read())
                            ret = (int)dataReader[0];
                        dataReader.Close();
                    }
                }
                catch (ApplicationException e)
                {

                }
                conn.Close();
            }
            return ret;
        }

Is this a good way to use a dll in my web application ?or there 's a way better than this ?

4

2 に答える 2

1

のような何らかの構成で接続文字列を使用することをお勧めしますweb.config

于 2012-08-08T09:03:52.290 に答える
1

これらの静的メソッドを使用して、ほとんど自分の足を撃ちました。おそらくベスト プラクティスは、インスタンス メソッドを使用するようにクラスをリファクタリングし、コンストラクターまたはプロパティを介して接続文字列を挿入することです。

静的メソッドをリファクタリングして接続文字列を含めることができませんか?

public static int Is_Valid_User(string p_u, string p_p, string connectionString)

[web|app]config 接続文字列への参照をハードコーディングすることもできますが、それは問題 (固定文字列への依存) を変更しただけで、解決しませんでした。

于 2012-08-08T09:13:42.960 に答える