How to connect Codeigniter 2.1.x with sqlsrv - sql-server

I have the following conf database
$db['default']['hostname'] = 'xx.xx.xx.xx,1433';
$db['default']['username'] = 'user';
$db['default']['password'] = 'pass';
$db['default']['database'] = 'dbname';
$db['default']['dbdriver'] = 'sqlsrv';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
Codeigniter get me the Unable to connect to database using the parameters entered...what's wrong? i try the following connection for $db['default']['hostname']
$db['default']['hostname'] = 'xx.xx.xx.xx,1433';
$db['default']['hostname'] = '(xx.xx.xx.xx),1433';
$db['default']['hostname'] = 'xx.xx.xx.xx:1433';
and it don't work
Any ideas? Thanks

Set
$db['default']['pconnect'] = false;
That should work.

You added hostname and port number together codeigniter has a setting to define port number
$db['default']['hostname'] = 'xx.xx.xx.xx';
$db['default']['username'] = 'user';
$db['default']['password'] = 'pass';
$db['default']['database'] = 'dbname';
$db['default']['dbdriver'] = 'sqlsrv';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
$db['default']['port'] = 1433;
For more details go to http://ellislab.com/codeigniter/user-guide/database/configuration.html

Related

Not able to update the data in more than one table in Asp .net MVC5

Here I am able to add the data in more than one table. Let i have 3 tables User, Franchise and Fee.
I am not able to update the data in more than one table,it throwing the exception:
A referential integrity constraint violation occurred: The property value(s) of 'User.Id' on one end of a relationship do not match the property value(s) of 'Franchise.UserId' on the other end.
Code:
public MessageResult SaveAndUpdateFranchisee(UserViewModel model)
{
var result = new MessageResult();
try
{
User userData = new User();
Franchise franchiseData = new Franchise();
var ExistUser = db.Users.Where(a => a.Id == model.Id).FirstOrDefault();
//Update record
if (model.Id > 0)
{
Fee feeData = new Fee
{
FranchiseeFee = model.FranchiseeFee,
PaymentTermsFranchiseFee = model.PaymentTermsFranchiseFee,
EquipmentCost = model.EquipmentCost,
PaymentTermsEquipmentCost = model.PaymentTermsEquipmentCost,
OtherFee = model.OtherFee,
PaymentTermsOtherFee = model.PaymentTermsOtherFee,
ConsumableStock = model.ConsumableStock,
PaymentTermsConsumableStock = model.PaymentTermsConsumableStock,
FrozenFoodStock = model.FrozenFoodStock,
PaymentTermsFrozenFoodStock = model.PaymentTermsFrozenFoodStock,
TotalAmountDue = model.TotalAmountDue,
TotalAmountPaid = model.TotalAmountPaid,
BalanceAmount = model.BalanceAmount,
LoyaltyFeePercentage = model.LoyaltyFeePercentage,
FixedMonthlyFee = model.FixedMonthlyFee,
Note = model.Note,
UserId = model.CurrentUserId,
LOIDocUrl = model.LOIDocUrl,
ModifiedDate = DateTime.Now
};
ExistUser.Email = model.Email;
//var pwd = SecutiryServices.EncodePasswordToBase64(model.Password);
//userData.Password = pwd;
ExistUser.Password = model.Password;
ExistUser.FirstName = model.FirstName;
ExistUser.MiddleName = model.MiddleName;
ExistUser.LastName = model.LastName;
ExistUser.FullName = model.FullName;
ExistUser.MobileNo = model.MobileNo;
ExistUser.ModifyDate = DateTime.Now;
franchiseData.Name = model.FullName;
franchiseData.MobileNo = model.MobileNo;
franchiseData.AlternateNo = model.AlternetNo;
franchiseData.CompanyPhoneNo = model.PhoneNo;
franchiseData.Address = model.Address;
franchiseData.City = model.City;
franchiseData.State = model.State;
franchiseData.PinCode = model.PinCode;
franchiseData.CompanyName = model.CompanyName;
franchiseData.CompanyAddress = model.CompanyAddress;
franchiseData.CompanyCity = model.CompanyCity;
franchiseData.CompanyState = model.CompanyState;
franchiseData.CompanyAddress = model.CompanyAddress;
franchiseData.CompanyPinCode = model.CompanyPinCode;
franchiseData.ModifiedDate = DateTime.Now;
userData.Franchises.Add(franchiseData);
foreach (var item in userData.Franchises)
{
item.Fees.Add(feeData);
}
db.Users.Attach(userData);
db.Entry(userData).State = System.Data.Entity.EntityState.Modified;
//db.Users.Add(userData);
db.SaveChanges();
result.Message = "Your franchise has been updated successfully..";
result.Status = true;
}
//For Insert recored..
else
{
Fee feeData = new Fee
{
FranchiseeFee = model.FranchiseeFee,
PaymentTermsFranchiseFee = model.PaymentTermsFranchiseFee,
EquipmentCost = model.EquipmentCost,
PaymentTermsEquipmentCost = model.PaymentTermsEquipmentCost,
OtherFee = model.OtherFee,
PaymentTermsOtherFee = model.PaymentTermsOtherFee,
ConsumableStock = model.ConsumableStock,
PaymentTermsConsumableStock = model.PaymentTermsConsumableStock,
FrozenFoodStock = model.FrozenFoodStock,
PaymentTermsFrozenFoodStock = model.PaymentTermsFrozenFoodStock,
TotalAmountDue = model.TotalAmountDue,
TotalAmountPaid = model.TotalAmountPaid,
BalanceAmount = model.BalanceAmount,
LoyaltyFeePercentage = model.LoyaltyFeePercentage,
FixedMonthlyFee = model.FixedMonthlyFee,
Note = model.Note,
UserId = model.CurrentUserId,
LOIDocUrl = model.LOIDocUrl,
CreatedDate = DateTime.Now
};
userData.Email = model.Email;
//var pwd = SecutiryServices.EncodePasswordToBase64(model.Password);
//userData.Password = pwd;
userData.Password = model.Password;
userData.FirstName = model.FirstName;
userData.FullName = model.FirstName + " " + model.LastName;
userData.LastName = model.LastName;
userData.MobileNo = model.MobileNo;
userData.IsActive = true;
userData.IsDelete = false;
userData.CreatedDate = DateTime.Now;
userData.UserTypeId = 2;
franchiseData.CompanyId = model.CurrentUserId;
franchiseData.Name = userData.FullName;
franchiseData.MobileNo = model.MobileNo;
franchiseData.AlternateNo = model.AlternetNo;
franchiseData.Address = model.Address;
franchiseData.City = model.City;
franchiseData.State = model.State;
franchiseData.PinCode = model.PinCode;
franchiseData.CompanyName = model.CompanyName;
franchiseData.CompanyPhoneNo = model.PhoneNo;
franchiseData.CompanyAddress = model.CompanyAddress;
franchiseData.CompanyCity = model.CompanyCity;
franchiseData.CompanyState = model.CompanyState;
franchiseData.CompanyAddress = model.CompanyAddress;
franchiseData.CompanyPinCode = model.CompanyPinCode;
franchiseData.CreatedDate = DateTime.Now;
franchiseData.IsActive = true;
userData.Franchises.Add(franchiseData);
foreach (var item in userData.Franchises)
{
item.Fees.Add(feeData);
}
db.Users.Add(userData);
db.SaveChanges();
//db.AddUserRole(userData.Id, 4);
result.Message = "Your franchisee has been created successfully..";
result.Status = true;
}
return result;
}
catch (Exception ex)
{
result.Message = "We are unable to process your request at this time. Please try again later.";
result.Status = false;
return result;
}
}
The error message is straightforward - your code is creating a new Franchise object but it never sets the franchiseData.UserId property.
Add this to your franchiseData population code before you call db.SaveChanges():
franchiseData.UserId = model.CurrentUserId;
BTW, you should add code verify that the current user has permission to set foreign-key reference properties (like UserId) directly from values read from submitted forms because otherwise any user could enter Id values belonging to other users and gain access to information they shouldn't have access to - or otherwise alter with your database.

set visibility trough property not working actionscript 3.0

This is my first post.
if (condition) {
trace("called");
p[1].visible = false;
j[1].visible = false;
}
With the code above "called" was printed in console but the both objects (buttons) still visible. Then when I try to put the set visibility (p[1].visible = false; and j[1].visible = false;) out from condition, it's work well.
I wonder what the problem here and how can I do set visibility with some condition?
[EDIT]
This is my actual source code. The code snippet above just to simple my question.
import flash.events.MouseEvent;
import flash.ui.Mouse;
import flash.events.Event;
stop();
var isInit:Boolean;
var val:Array;
var p:Array;
if (!isInit)
{
isInit = initial();
}
function initial():Boolean
{
trace("init");
val = new Array();
val[1] = 0;
val[2] = 0;
val[3] = 0;
val[4] = 0;
val[5] = 0;
val[6] = 0;
pinit();
jinit();
ainit();
binit();
cinit();
dinit();
einit();
return true;
}
function pinit():void
{
p = new Array();
p[1] = p1;
p[2] = p2;
p[3] = p3;
}
// event listener works
p[1].addEventListener(MouseEvent.CLICK, function (event:MouseEvent):void {
p[1].visible = false;
});
p[2].addEventListener(MouseEvent.CLICK, function (event:MouseEvent):void {
p[2].visible = false;
});
if (isInit)
{
trace("set visibility"); // this is printed as well
var i:int;
for (i = 1; i <= 3; i++)
{
setVisibility(i, val[i]);
}
}
function setVisibility(num:int, val:int):void
{
if (val==0)
{
p[num].visible = true;
j[num].visible = true;
}
else if (val==1)
{
trace("one");
p[num].visible = false;
j[num].visible = false;
}
else if (val==2)
{
trace("two");
p[num].visible = false;
j[num].visible = false;
a[num].visible = false;
}
else if (val==3)
{
trace("three");
p[num].visible = false;
j[num].visible = false;
a[num].visible = false;
b[num].visible = false;
}
else if (val==4)
{
trace("four");
p[num].visible = false;
j[num].visible = false;
a[num].visible = false;
b[num].visible = false;
c[num].visible = false;
}
else if (val==5)
{
trace("five");
p[num].visible = false;
j[num].visible = false;
a[num].visible = false;
b[num].visible = false;
c[num].visible = false;
d[num].visible = false;
}
}
The ainit, binit, cinit, etc functions are in another layer (on same frame) because the objects are there. The "one", "two", "three", "four", or "five" is printed but the visibility not set correctly.
Just to make your code simpler and easier to read.
With your val array you can populate it like this
val = new Array (0,0,0,0,0,0,0);
Yes this has seven numbers as an array starts at 0. You don't have to reference it but I would populate it just to make it look nicer.
I also changed the if else bit at the end to this:
switch (val){
case 0:
p[num].visible = true;
j[num].visible = true;
break;
case 1:
trace("one");
p[num].visible = false;
j[num].visible = false;
break;
case 2:
trace("two");
p[num].visible = false;
j[num].visible = false;
a[num].visible = false;
break;
case 3:
trace("three");
p[num].visible = false;
j[num].visible = false;
a[num].visible = false;
b[num].visible = false;
break;
case 4:
trace("four");
p[num].visible = false;
j[num].visible = false;
a[num].visible = false;
b[num].visible = false;
c[num].visible = false;
break;
case 5:
trace("five");
p[num].visible = false;
j[num].visible = false;
a[num].visible = false;
b[num].visible = false;
c[num].visible = false;
d[num].visible = false;
break;
}
As to your actual problem I don't think you can change a button from an array as it would become a copy of the button not the button itself (Hope that makes sense). I would still have the arrays but instead of the button visibility I'd use Booleans. So that at the end you could put:
btnButton.visible = p1;
Hope that's all Okay and of some use.

How to get GridView style in Exported Excel

I have migrated my application to Dev Express 15.2.After migration data is not exporting in GridView style.Like alternate row color,Font ..etc.Do we have any option to export the data same as like in grid.
Designer:
this.gridView1.Appearance.EvenRow.BackColor = System.Drawing.Color.Khaki;
this.gridView1.Appearance.EvenRow.Options.UseBackColor = true;
this.gridView1.Appearance.GroupPanel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(74)))), ((int)(((byte)(74)))), ((int)(((byte)(74)))));
this.gridView1.Appearance.GroupPanel.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Bold);
this.gridView1.Appearance.GroupPanel.Options.UseBackColor = true;
this.gridView1.Appearance.GroupPanel.Options.UseFont = true;
this.gridView1.Appearance.HeaderPanel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(194)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
this.gridView1.Appearance.HeaderPanel.Options.UseBackColor = true;
this.gridView1.AppearancePrint.EvenRow.BackColor = System.Drawing.Color.Khaki;
this.gridView1.AppearancePrint.EvenRow.Options.UseBackColor = true;
this.gridView1.Columns.AddRange(new DevExpress.XtraGrid.Columns.GridColumn[] {
this.gridColumn1,
this.gridColumn2,
this.gridColumn3,
this.gridColumn4,
this.gridColumn5});
this.gridView1.GridControl = this.gridControl1;
this.gridView1.GroupSummary.AddRange(new DevExpress.XtraGrid.GridSummaryItem[] {
new DevExpress.XtraGrid.GridGroupSummaryItem(DevExpress.Data.SummaryItemType.Count, "OrderID", null, "")});
this.gridView1.Name = "gridView1";
this.gridView1.OptionsView.EnableAppearanceEvenRow = true;
Code in cs file
if(ext == "xlsx")
{
XlsxExportOptionsEx options = new XlsxExportOptionsEx();
options.ShowGridLines = false;
options.AllowSortingAndFiltering = DevExpress.Utils.DefaultBoolean.False;
options.ExportType = DevExpress.Export.ExportType.WYSIWYG;
exportView.ExportToXlsx(filename, options);
}
By setting following properties issue is solved.
((DevExpress.XtraGrid.Views.Grid.GridView)gridControl1.MainView).OptionsPrint.EnableAppearanceEvenRow = true;
((DevExpress.XtraGrid.Views.Grid.GridView)gridControl1.MainView).OptionsPrint.UsePrintStyles = false;

Multiple database- access data from the 3rd database using codeigniter

I am using codeigniter.I want to use 3 database in my project.I set the database.php file us,
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'marketer_fp';
$db['default']['password'] = 'xxxxx';
$db['default']['database'] = 'marketer_fpr';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
$db['wpdb']['hostname'] = "localhost";
$db['wpdb']['username'] = "marketer_fprr";
$db['wpdb']['password'] = "yyyy";
$db['wpdb']['database'] = "marketer_mark";
$db['wpdb']['dbdriver'] = "mysql";
$db['wpdb']['dbprefix'] = "";
$db['wpdb']['pconnect'] = FALSE;
$db['wpdb']['db_debug'] = TRUE;
$db['wpdb']['cache_on'] = FALSE;
$db['wpdb']['cachedir'] = "";
$db['wpdb']['char_set'] = "utf8";
$db['wpdb']['dbcollat'] = "utf8_general_ci";
$db['wpfashn']['hostname'] = "localhost";
$db['wpfashn']['username'] = "marketer_fprr";
$db['wpfashn']['password'] = "yyyy";
$db['wpfashn']['database'] = "marketer_fah";
$db['wpfashn']['dbdriver'] = "mysql";
$db['wpfashn']['dbprefix'] = "";
$db['wpfashn']['pconnect'] = FALSE;
$db['wpfashn']['db_debug'] = TRUE;
$db['wpfashn']['cache_on'] = FALSE;
$db['wpfashn']['cachedir'] = "";
$db['wpfashn']['char_set'] = "utf8";
$db['wpfashn']['dbcollat'] = "utf8_general_ci";
The second and third database have same username and password.
In the controller ,inside construct function these 3 database are called.
$this->db3 =$this->load->database('wpfashn', TRUE);
$this->db2 =$this->load->database('wpdb', TRUE);
$this->db =$this->load->database('default', TRUE);
Inside another function a query is written,which should be executed by using the database 3.
$check=$this->db3->query("select * from mm_use_dat where wp_user_id='2'");
print_r($check->result());
this query return an empty array even if value present in the database.What should be the problem?Please help me to find a solution!

Populate 100 images using an If loop

I'm currently populating 100 images using the following code, but I'm sure there's a more economical way of doing it with an If statement:
mapblock01.image = [UIImage imageNamed:#"block.png"]; mapblock01.hidden = TRUE;
mapblock02.image = [UIImage imageNamed:#"block.png"]; mapblock02.hidden = TRUE;
mapblock03.image = [UIImage imageNamed:#"block.png"]; mapblock03.hidden = TRUE;
mapblock04.image = [UIImage imageNamed:#"block.png"]; mapblock04.hidden = TRUE;
mapblock05.image = [UIImage imageNamed:#"block.png"]; mapblock05.hidden = TRUE;
------>
mapblock99.image = [UIImage imageNamed:#"block.png"]; mapblock99.hidden = TRUE;
mapblock100.image = [UIImage imageNamed:#"block.png"]; mapblock100.hidden = TRUE;
Any ideas?
for it, you can give tag for each UIImageView as 1,2,3..100 and set image as below:
for (int i = 0 ; i < 100 ; i++) {
UIImageView *imageV = (UIImageView *)[self.view viewWithTag:i];
imageV.image = [UIImage imageNamed:#"block.png"];
imageV.hidden = TRUE;
}
}

Resources