示例#1
0
        internal void StartCreateQueryTalkBase()
        {
            Task.Factory.StartNew(() =>
            {
                try
                {
                    var connBuilder            = new SqlConnectionStringBuilder(ConnBuilder.ToString());
                    connBuilder.InitialCatalog = "master";
                    CreateQueryTalkBase(connBuilder);

                    // store QueryTalkBase connection string
                    connBuilder.InitialCatalog = "QueryTalkBase";
                    Registry.WriteQueryTalkBaseConnection(connBuilder.ToString());
                }
                catch (Exception ex)
                {
                    if (!HasQueryTalkBase())
                    {
                        CurrentProcessException = ex;
                    }
                    else
                    {
                        CurrentProcessException = null;
                    }
                }
                finally
                {
                    QueryTalkBaseCreationCompleted?.Invoke(this, new EventArgs());
                }
            });
        }
    public void ImplementEntityClient()
    {
        try
        {
            String provider     = "System.Data.SqlClient";
            String serverName   = "localhost";
            String databaseName = "dbname";

            SqlConnectionStringBuilder donnBuilder = new SqlConnectionStringBuilder();
            ConnBuilder.DataSource     = serverName;
            ConnBuilder.InitialCatalog = databaseName;

            EntityConnectionStringBuilder efBuilder = new EntityConnectionStringBuilder();
            efBuilder.Provider = Provider;
            efBuilder.ProviderConnectionString = ConnBuilder.ToString();
            efBuilder.Metadata = @"*csdl, *ssdl, *msl";

            EntityConnection Connection = new EntityConnection(EfBuilder.ToString());
            // EntityConnection connection = new EntityConnection(ConnectionStringHere);

            // Transactions
            EntityFrameworkSamplesEntities Context = new EntityFrameworkSamplesEntities();

            // context does not provide database so use Context.Database object
            IDbTransaction TransactionInstance = Context.Database.Connection.BeginTransaction();
            try
            {
                // Do Something
                Context.SaveChanges();
                TransactionInstance.Commit();
            }
            catch (EntityCommandExecutionException)
            {
                TransactionInstance.Rollback();
            }

            EntityFrameworkSamplesEntities Context = new EntityFrameworkSamplesEntities();
            using (TransactionScope CurrentScope = new TransactionScope())
            {
                try
                {
                    Context.SaveChanges();
                    CurrentScope.Complete();
                }
                catch (EntityCommandExecutionException)
                {
                    //Handle the exception as you normally would
                    //It won't be committed so transaction wise you're done
                }
            }
        }
        catch (Exception ex)
        {
        }
        finally
        {
        }
    }
示例#3
0
        internal bool HasQueryTalkBase()
        {
            try
            {
                d.SetConnection(connKey => new ConnectionData(ConnBuilder.ToString(), 0));

                return(d
                       .From("sys.sysdatabases")
                       .Where("name", "QueryTalkBase")
                       .Select("name")
                       .Go <Row <string> >()
                       .Any());
            }
            catch
            {
                return(false);
            }
        }
示例#4
0
 internal void ShowQueryTalkBase()
 {
     try
     {
         ConnBuilder.InitialCatalog = "QueryTalkBase";
         var connString = ConnBuilder.ToString();
         d.SetConnection(connString);
         ConnBuilder.InitialCatalog = "master";   // get back the default value
         d.AsNon("Database Table Loader")
         .Declare("@ccTable", d.Concatenator)
         .BeginCursor(d.From("INFORMATION_SCHEMA.TABLES")
                      .OrderBy("TABLE_NAME")
                      .Select((d.Quotename("TABLE_SCHEMA")).Plus(".".L()).Plus(d.Quotename("TABLE_NAME"))).EndView())
         .IntoVars("@ccTable")
         .FromSelect("@ccTable")
         .FetchNext()
         .EndCursor()
         .Test();
     }
     catch { }
 }