1
Vote

Suggested Changes

description

Hi,

I would like to ask if you may add a few changes to the SQL server part.

With the connection settings add capability to change the connection timeout like below.
public class SqlConnectionInfo : ICloneable
{
    public SqlConnectionInfo(string serverName, string databaseName)
    {
        ServerName = serverName;
        DatabaseName = databaseName;
        Timeout = 30;
    }

    public string ServerName { get; set; }
    public string InstanceName { get; set; }
    public string DatabaseName { get; set; }
    public string UserDomain { get; set; }
    public string UserName { get; set; }
    public string Password { get; set; }
    public int Timeout { get; set; }

    public object Clone()
    {
        return new SqlConnectionInfo(this.ServerName, this.DatabaseName)
        {
            InstanceName = this.InstanceName,
            UserDomain = this.UserDomain,
            UserName = this.UserName,
            Password = this.Password,
            Timeout = this.Timeout
        };
    }
}
private string BuildConnectionString(SqlConnectionInfo info)
    {
        var sb = new StringBuilder();

        if (string.IsNullOrEmpty(m_info.InstanceName))
        {
            sb.AppendFormat("Data Source={0};", info.ServerName);
        }
        else
        {
            sb.AppendFormat("Data Source={0}\\{1};", info.ServerName, info.InstanceName);
        }

        sb.AppendFormat("Initial Catalog={0};", info.DatabaseName);

        if (string.IsNullOrEmpty(info.UserDomain))
        {
            sb.AppendFormat("User ID={0};", info.UserName);
        }
        else
        {
            sb.AppendFormat("User ID={0}\\{1};", info.UserDomain, info.UserName);
        }

        sb.AppendFormat("Password={0};", info.Password);

        sb.Append("MultipleActiveResultSets=True;");

        sb.AppendFormat("Connection Timeout={0};", info.Timeout);

        return sb.ToString();
    }
I am from a country where we do not have fast connections and these changes helped me a lot.

The other one is to make the RowVersion field populate as follow to be like the SQL convert to big int.
private static Int64 GetDbVersion(byte[] dbVersion)
    {
        Int64 version = 0;
        if (BitConverter.IsLittleEndian)
        {
            var clone = dbVersion.Clone() as byte[];
            Array.Reverse(clone);
            version = BitConverter.ToInt64(clone, 0);
        }
        else
        { version = BitConverter.ToInt64(dbVersion, 0); }
        return version;
    }
I your select statement the following part
else if (field.IsRowVersion)
                                    {
                                        // sql stores this an 8-byte array
                                        field.PropertyInfo.SetValue(item, GetDbVersion((byte[])value), null);//BitConverter.ToInt64((byte[])value, 0)
                                    }
Completing my backend now then starting on Android and Windows 7 phone with the SQLLite part. This is truly an awesome project!!!!!!!!!

comments