Exemple #1
0
 private void CreateDataBase( )
 {
     DS           = (GxDataStore)(context.GetDataStore("Default"));
     ErrCode      = DS.Connection.FullConnect();
     DataBaseName = DS.Connection.Database;
     if (ErrCode != 0)
     {
         DS.Connection.Database = "";
         ErrCode = DS.Connection.FullConnect();
         if (ErrCode == 0)
         {
             try
             {
                 GeneXus.Reorg.GXReorganization.AddMsg(GXResourceManager.GetMessage("GXM_dbcrea") + " " + DataBaseName, null);
                 cmdBuffer     = "CREATE DATABASE " + "[" + DataBaseName + "]";
                 RGZ           = new GxCommand(dsDefault.Db, cmdBuffer, dsDefault, 0, true, false, null);
                 RGZ.ErrorMask = GxErrorMask.GX_NOMASK | GxErrorMask.GX_MASKLOOPLOCK;
                 RGZ.ExecuteStmt();
                 RGZ.Drop();
                 Count = 1;
             }
             catch (Exception ex)
             {
                 ErrCode = 1;
                 GeneXus.Reorg.GXReorganization.AddMsg(ex.Message, null);
                 throw ex;
             }
             ErrCode = DS.Connection.Disconnect();
             DS.Connection.Database = DataBaseName;
             ErrCode = DS.Connection.FullConnect();
             while ((ErrCode != 0) && (Count > 0) && (Count < 30))
             {
                 Res     = GXUtil.Sleep(1);
                 ErrCode = DS.Connection.FullConnect();
                 Count   = (short)(Count + 1);
             }
             setupDB = 0;
             if ((setupDB == 1) || GeneXus.Configuration.Preferences.MustSetupDB( ))
             {
                 defaultUsers = GXUtil.DefaultWebUser(context);
                 short gxidx;
                 gxidx = 1;
                 while (gxidx <= defaultUsers.Count)
                 {
                     defaultUser = ((String)defaultUsers.Item(gxidx));
                     try
                     {
                         GeneXus.Reorg.GXReorganization.AddMsg(GXResourceManager.GetMessage("GXM_dbadduser", new   object[]  { defaultUser, DataBaseName }), null);
                         cmdBuffer     = "CREATE LOGIN " + "[" + defaultUser + "]" + " FROM WINDOWS";
                         RGZ           = new GxCommand(dsDefault.Db, cmdBuffer, dsDefault, 0, true, false, null);
                         RGZ.ErrorMask = GxErrorMask.GX_NOMASK | GxErrorMask.GX_MASKLOOPLOCK;
                         RGZ.ExecuteStmt();
                         RGZ.Drop();
                     }
                     catch (Exception ex)
                     {
                     }
                     try
                     {
                         cmdBuffer     = "CREATE USER " + "[" + defaultUser + "]" + " FOR LOGIN " + "[" + defaultUser + "]";
                         RGZ           = new GxCommand(dsDefault.Db, cmdBuffer, dsDefault, 0, true, false, null);
                         RGZ.ErrorMask = GxErrorMask.GX_NOMASK | GxErrorMask.GX_MASKLOOPLOCK;
                         RGZ.ExecuteStmt();
                         RGZ.Drop();
                     }
                     catch (Exception ex)
                     {
                     }
                     try
                     {
                         cmdBuffer     = "EXEC sp_addrolemember N'db_datareader', N'" + defaultUser + "'";
                         RGZ           = new GxCommand(dsDefault.Db, cmdBuffer, dsDefault, 0, true, false, null);
                         RGZ.ErrorMask = GxErrorMask.GX_NOMASK | GxErrorMask.GX_MASKLOOPLOCK;
                         RGZ.ExecuteStmt();
                         RGZ.Drop();
                     }
                     catch (Exception ex)
                     {
                     }
                     try
                     {
                         cmdBuffer     = "EXEC sp_addrolemember N'db_datawriter', N'" + defaultUser + "'";
                         RGZ           = new GxCommand(dsDefault.Db, cmdBuffer, dsDefault, 0, true, false, null);
                         RGZ.ErrorMask = GxErrorMask.GX_NOMASK | GxErrorMask.GX_MASKLOOPLOCK;
                         RGZ.ExecuteStmt();
                         RGZ.Drop();
                     }
                     catch (Exception ex)
                     {
                     }
                     gxidx = (short)(gxidx + 1);
                 }
             }
         }
         if (ErrCode != 0)
         {
             ErrMsg = DS.ErrDescription;
             GeneXus.Reorg.GXReorganization.AddMsg(ErrMsg, null);
             ErrCode = 1;
             throw new Exception(ErrMsg);
         }
     }
 }