This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I have a wcf service with the following web.config in the server.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="myconnection" connectionString="myconnectionstr"/>
</connectionStrings>
<system.serviceModel>
<services>
<service behaviorConfiguration="PSWebServis.PServisBehavior" name="PSWebServis.PServis">
<endpoint address="" binding="wsHttpBinding" contract="PSWebServis.IPServis" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="PSWebServis.PServisBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
and this is related part in web.config in client.
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IPServis" />
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://sunucu:8000/PServis.svc" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IPServis" contract="PSWebServis.IPServis"
name="WSHttpBinding_IPServis">
<identity>
<servicePrincipalName value="host/SUNUCU" />
</identity>
</endpoint>
</client>
Here is a part of my interface in the service
[ServiceContract]
public interface IPServis
{
[OperationContract]
string InsertMusteri(MusterilerModel musteri);
}
and related part in service class.
public class PServis : IPServis
{
public string InsertMusteri(MusterilerModel musteri)
{
if (musteri != null)
{
DataTable dtSonuc = new DataTable();
SqlCommand command = new SqlCommand("InsertMusteriModel", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("#musteriTablo", musteri.KayitTablosu);
command.Parameters.AddWithValue("#telefonTablo", musteri.TelefonKayit);
command.Parameters.AddWithValue("#adresTablo", musteri.AdresKayit);
connection.Open();
command.ExecuteNonQuery();
SqlDataAdapter adapter = new SqlDataAdapter(command);
adapter.Fill(dtSonuc);
connection.Close();
return dtSonuc.Rows[0]["IslemDurum"].ToString();
}
return "Başarısız";
}
}
My MusterilerModel class:
[DataContract]
public class MusterilerModel
{
[DataMember(Order=0)]
public int MusteriID { set; get; }
[DataMember(Order = 1)]
public string Ad { set; get; }
[DataMember(Order = 2)]
public string Soyad { set; get; }
[DataMember(Order=3)]
public string KullaniciAdi { set; get; }
[DataMember(Order = 4)]
public string Email { set; get; }
[DataMember(Order = 5)]
public DateTime DogumTarihi { set; get; }
[DataMember(Order=6)]
public string GrupAdi { set; get; }
[DataMember(Order=7)]
public int Renk { set; get; }
[DataMember(Order=8)]
public decimal Bakiye { set; get; }
[DataMember(Order=9)]
public string Adres { set; get; }
[DataMember(Order=10)]
public string AdresAciklamasi { set; get; }
[DataMember(Order=11)]
public string Firma { set; get; }
[DataMember(Order=12)]
public string VergiDairesi { set; get; }
[DataMember(Order=13)]
public string VergiNo { set; get; }
[DataMember(Order=14)]
public int BayiID { set; get; }
[DataMember(Order=15)]
public string Il { set; get; }
[DataMember(Order = 16)]
public string Ilce { set; get; }
[DataMember(Order = 17)]
public decimal YemekPara { get; set; }
[DataMember(Order=18)]
public string Sifre { set; get; }
[DataMember(Order=19)]
public int GrupID { set; get; }
[DataMember(Order=20)]
public string BayiAdi { set; get; }
[DataMember(Order=21)]
public int SehirID { set; get; }
[DataMember(Order=22)]
public int IlceID { set; get; }
[DataMember(Order=23)]
public DateTime EvlilikYilDonumu { set; get; }
[DataMember(Order=24)]
public DateTime KayitTarihi { set; get; }
[DataMember(Order=25)]
public string KayitEdenPersonel { set; get; }
[DataMember(Order=26)]
public int KayitEdenPersonelID { set; get; }
[DataMember(Order=27)]
public bool AktifMi { set; get; }
[DataMember(Order=28)]
public string Aciklama { set; get; }
[DataMember(Order=29)]
public string OzelKod { set; get; }
[DataMember(Order=30)]
public int SatisID { set; get; }
[DataMember(Order=31)]
public DataTable KayitTablosu { set; get; }
[DataMember(Order=32)]
public DataTable TelefonKayit { set; get; }
[DataMember(Order=33)]
public DataTable AdresKayit { set; get; }
}
When i try to use InsertMusteri method, there are 2 records in the database. As you see, i put my information into datatable and send it to the service. I checked, if datatable has more than 1 value but that was not the problem. I don't know where is the problem.
Comment this line
command.ExecuteNonQuery();
And check if it's work properly.
I think "Fill" command executs your command.
Related
I can't figure out what the problem is. I am using Entity Framework 6 to access an Oracle 12c Database. When I try to add a new row to the table I get the ORA-01400 error in my title. However, when I look at the values that I am attempting to add in the debugger they are not null.
protected void InsertButton_Click(object sender, EventArgs e)
{
AddNewPartner(GetFields());
}
public void AddNewPartner(FTP_GET_TESTING ftpPartner)
{
using (Entities myEntities = new Entities())
{
myEntities.FTP_GET_TESTING.Add(ftpPartner);
myEntities.SaveChanges();
}
}
Update
Here is the model(it is Data First):
public partial class FTP_GET_TESTING
{
public string FTP_LOOKUP_ID { get; set; }
public string FTP_HOST { get; set; }
public string USER_NAME { get; set; }
public string PASSWORD { get; set; }
public string ADAPTER { get; set; }
public string FTP_MODE { get; set; }
public string PICKUP_FOLDER { get; set; }
public string DESTINATION_FOLDER { get; set; }
public string DELIVERY_FILENAME { get; set; }
public string DESTINATION_BP { get; set; }
public string ARCHIVE_FOLDER { get; set; }
public string REMOTE_ARCHIVE_FILE_EXTENSION { get; set; }
public string REMOTE_ARCHIVE_DIRECTORY { get; set; }
public string REMOTE_FILE_DELETE { get; set; }
public string FTP_DOWN { get; set; }
public string FILTER { get; set; }
public string LISTSIZE_FLAG { get; set; }
public decimal LIST_MAX { get; set; }
public string CHECK_FILE_SIZE { get; set; }
public string PGP_DECRYPT { get; set; }
public string PGP_PASSPHRASE { get; set; }
public string CONNECTION_TYPE { get; set; }
public string REPRESENTATION_TYPE { get; set; }
public string FTPS_CACERTIFICATE_ID { get; set; }
public string FTPS_CIPHER_STRENGTH { get; set; }
public string PORT { get; set; }
public string FTPS_SSL { get; set; }
public string FTPS_SYSTEM_CERT_ID { get; set; }
public string SFTP_COMPRESSION { get; set; }
public string SFTP_KNOWNHOST_KEY_ID { get; set; }
public string SFTP_PREF_AUTH_METHOD { get; set; }
public string SFTP_PREFERRED_CIPHER { get; set; }
public string SFTP_PREFERRED_MAC { get; set; }
public string SFTP_USER_ID_KEY_ID { get; set; }
public string FMC_RELATIONSHIP_NAME { get; set; }
public string USER_FIELD1 { get; set; }
public string USER_FIELD2 { get; set; }
public string USER_FIELD3 { get; set; }
public string NOTES { get; set; }
public Nullable<System.DateTime> LAST_UPDATE { get; set; }
public string LAST_USER_UPDATE { get; set; }
public string PARTNER_NAME { get; set; }
public string MAILBOX_ID { get; set; }
public string REMEDY_QUEUE { get; set; }
public string SCHEDULE { get; set; }
public Nullable<decimal> ALERT_FREQUENCY { get; set; }
public string PRIORITY { get; set; }
public string CONTACT_NAME { get; set; }
public string CONTACT_EMAIL { get; set; }
public string CONTACT_PHONE { get; set; }
public string FTP_SEND_LOOKUP_ID { get; set; }
}
I verify the data added using the immediate window in the debugger.
myEntities.FTP_GET_TESTING.Add(ftpGet);
{GP_GENERIC_FTP_GET_TESTING}
ADAPTER: "FTP_Client_Adapter_Group"
ALERT_FREQUENCY: 120
ARCHIVE_FOLDER: ""
CHECK_FILE_SIZE: "NO"
CONNECTION_TYPE: "PASSIVE"
CONTACT_EMAIL: "Atest"
CONTACT_NAME: "Atest"
CONTACT_PHONE: "Atest"
DELIVERY_FILENAME: ""
DESTINATION_BP: ""
DESTINATION_FOLDER: ""
FILTER: ""
FMC_RELATIONSHIP_NAME: ""
FTPS_CACERTIFICATE_ID: ""
FTPS_CIPHER_STRENGTH: ""
FTPS_SSL: ""
FTPS_SYSTEM_CERT_ID: ""
FTP_DOWN: "N"
FTP_HOST: "Change"
FTP_LOOKUP_ID: "AnotherTest4"
FTP_MODE: "FTP"
FTP_SEND_LOOKUP_ID: ""
LAST_UPDATE: {12/28/2015 8:49:49 AM}
LAST_USER_UPDATE: "driver"
LISTSIZE_FLAG: "TRUE"
LIST_MAX: 520
MAILBOX_ID: ""
NOTES: "Atest"
PARTNER_NAME: "Atest"
PASSWORD: "Atest"
PGP_DECRYPT: "N"
PGP_PASSPHRASE: ""
PICKUP_FOLDER: ""
PORT: "21"
PRIORITY: "8x5"
REMEDY_QUEUE: "Atest"
REMOTE_ARCHIVE_DIRECTORY: ""
REMOTE_ARCHIVE_FILE_EXTENSION: ""
REMOTE_FILE_DELETE: "Y"
REPRESENTATION_TYPE: "BINARY"
SCHEDULE: "60MIN"
SFTP_COMPRESSION: ""
SFTP_KNOWNHOST_KEY_ID: ""
SFTP_PREFERRED_CIPHER: "blowfish-cbc"
SFTP_PREFERRED_MAC: ""
SFTP_PREF_AUTH_METHOD: ""
SFTP_USER_ID_KEY_ID: ""
USER_FIELD1: ""
USER_FIELD2: ""
USER_FIELD3: ""
USER_NAME: "Atest"
and I think this is the config info you wanted to see.
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
What else do I need to add here to help figure out the problem?
To fix this I did two things. First I deleted the model FTP_GET_TESTING and then I compared the primary key(FTP_LOOKUP_ID) in the testing table to the PK in the non testing table and there were some differences.
In design view of the table FTP_GET_TESTING my PK Constraint was named SYS_C0027857 I changed it to FTP_GET_TESTING_PK. I also changed the name of the index to match the constraint name FTP_GET_TESTING_PK. Then I added the table back into my model and it worked perfectly.
I am not sure if changing the PK name in constraints and indexes fixed the issue or if simply deleting and re-adding did the trick.
If anyone cares to add some input on this for future viewers, and so that I can understand what happened a little more I would appreciate it.
I am new to MVC and I have already created Database after we generated the ADO entity data model called HRContextEntities and we created just a bankviewmodel and its Repository and its Index view to display the Database Banks in a List:
Context :
public partial class HRContextEntities : DbContext
{
public HRContextEntities()
: base("name=HRContextEntities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public virtual DbSet<ACTIONS> ACTIONS { get; set; }
public virtual DbSet<BANKS> BANKS { get; set; }
public virtual DbSet<EMP_ALAWA> EMP_ALAWA { get; set; }
public virtual DbSet<EMP_CARDS> EMP_CARDS { get; set; }
public virtual DbSet<EMP_DAORA> EMP_DAORA { get; set; }
public virtual DbSet<EMP_DEGREES> EMP_DEGREES { get; set; }
public virtual DbSet<EMP_DEGREES_WORKERS> EMP_DEGREES_WORKERS { get; set; }
public virtual DbSet<EMP_DISSENT> EMP_DISSENT { get; set; }
public virtual DbSet<EMP_EMPLOYEES> EMP_EMPLOYEES { get; set; }
public virtual DbSet<EMP_ENDEMP> EMP_ENDEMP { get; set; }
public virtual DbSet<EMP_ENTEDAB> EMP_ENTEDAB { get; set; }
public virtual DbSet<EMP_EQRAR> EMP_EQRAR { get; set; }
public virtual DbSet<EMP_HASMIAT> EMP_HASMIAT { get; set; }
public virtual DbSet<EMP_HOLIDAYS> EMP_HOLIDAYS { get; set; }
public virtual DbSet<EMP_JOBS> EMP_JOBS { get; set; }
...............................
Bank View Model :
public class BankViewModel
{
public decimal BankID { get; set; }
public string BankName { get; set; }
public string BankSymbol { get; set; }
}
Bank Repository class:
public class BankRepository
{
HRContextEntities db = new HRContextEntities();
public BankViewModel[] GetAll(int? take, int? skip)
{
return db.BANKS.Select(s => new BankViewModel { BankID = s.ID, BankName = s.NAME })
.OrderBy(s => s.BankID).Skip(skip != null ? skip.Value : 0)
.Take(take != null ? take.Value : int.MaxValue).ToArray();
}
}
_Banks Partial View from:
#model IEnumerable<HumanResourceManagement.Models.BankViewModel>
#foreach (var item in Model)
{
<tr class="odd gradeX">
<td>
#item.BankID
</td>
<td>
#item.BankName
</td>
<td>
RYD
</td>
</tr>
}
Exception:
Additional information: Failed to set database initializer of type 'MyProject.Context.Config.ContextInitializer, MyProject.Context' for DbContext type 'App.Context.Default, App.Context' specified in the application configuration. See inner exception for details.
web.config
<contexts>
<context type="App.Context.Default, App.Context">
<databaseInitializer type="MyProject.Context.Config.ContextInitializer, MyProject.Context" />
<!--<databaseInitializer type="MyProject.Context.Config.ContextInitializer, MyProject.Context" />-->
</context>
</contexts>
so what is the solution for this exception
I think your problem lies in your web.config file:
<contexts>
<context type="App.Context.Default, App.Context">
<databaseInitializer type="MyProject.Context.Config.ContextInitializer, MyProject.Context" />
</context>
</contexts>
The context type specifies the fully qualified context class name and the assembly it's in, and the databaseinitializer type specifies the fully qualified name of the initializer class and the assembly it's in. Read this for more info.
Basically, the second param for context type AND databaseinitializer should be the project assembly, not the context. So it should follow this pattern:
<context type=" Blogging.BlogContext, MyAssembly">
<databaseInitializer type="Blogging.MyCustomBlogInitializer, MyAssembly" />
</context>
So in your code, try this (I think your assembly is MyProject):
<contexts>
<context type="MyProject.App.Context, MyProject">
<databaseInitializer type="MyProject.Context.Config.ContextInitializer, MyProject" />
</context>
</contexts>
I have a problem to scaffolding my model.
I get following error "object reference not set to an instance of an object"
My model :
public class Position
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long PositionID { get; set; }
public long OfferID { get; set; }
[Required]
[Display(Name = "Positie omschrijving")]
public string Name { get; set; }
[Required]
public int PositionNr { get; set; }
[Required]
public double WorkingHeight { get; set; }
public long PalletTypeID { get; set; }
public long MotorTypeID { get; set; }
public long Enveriment { get; set; }
}
My DBContext :
public class FlowContext : DbContext
{
public DbSet<Position> Positions { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
this.Configuration.LazyLoadingEnabled = true;
//Positie
modelBuilder.Entity<Position>()
.HasKey(j => j.PositionID);
}
}
My connection string in web.config
<connectionStrings>
<add name="FlowContext" connectionString="data source=.\SqlExpress; Integrated Security=True;Initial Catalog=Flow;" providerName="System.Data.SqlClient" />
public class project
{
public int id { get; set; }
public string ProjectName { get; set; }
public string Description { get; set; }
public string Category { get; set; }
public int UserprojectId { get; set; }
public int? SponserId { get; set; }
public decimal Cost { get; set; }
public DateTime CreatedTime { get; set; }
public DateTime EstimateTime { get; set; }
}
public class projectDB : DbContext
{
public DbSet<project> projects { get; set; }
}
and this model
public class sponser
{
public int id { get; set; }
public string FirstName { get; set; }
public string lastName { get; set; }
public string CompanyName { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public DateTime DateRegister { get; set; }
public String CompanyPhone { get; set; }
public string CellPhone { get; set; }
public string Email { get; set; }
public bool EmailConfirmation { get; set; }
public string Country { get; set; }
public string City { get; set; }
public string PostalCode { get; set; }
public String Address { get; set; }
}
public class sponserDB : DbContext
{
public DbSet<sponser> sponsers { get; set; }
}
and in my web confige file
i add this this name
<add name="SponseringDB"
connectionString="Data Source=(localdb)\v11.0;Initial Catalog=sponseringDB;Integrated Security=True"
providerName="System.Data.SqlServerCe.4.0"
/>
When run this and create some Record for me it made two database first sponseringDb and second is projectDb I want to use one database.
Need suggestions on achieving this.
You've got two classes inherit by DbContext and that is the reason why 2 database are created, if you want to have just one databe ie: projectDB
change you projectDB class to
public class projectDB : DbContext
{
public projectDB () : base("projectDBConnectionString") //<- name of your connection string
{
}
public DbSet<project> projects { get; set; }
public DbSet<sponser> sponsers { get; set; }
}
and in your web config add connection string named 'projectDBConnectionString' ie:
<add name="projectDBConnectionString"
connectionString="Data Source=(localdb)\v11.0;Initial Catalog=sponseringDB;Integrated Security=True"
providerName="System.Data.SqlServerCe.4.0"
/>
and now your can rid off connection string 'SponseringDB' from web.config and delete class 'sponserDB'
Hope that will help
i want to stop form submit by client side validation done by models attribute. i have done every possibilities but mot success.. please look this code:
My Model is
[Key]
public int User_ID { get; set; }
[Required(ErrorMessage = "* Please Enter FirstName")]
public string User_FN { get; set; }
[Required(ErrorMessage = "* Please Enter MiddleName")]
public string User_MN { get; set; }
[Required(ErrorMessage = "* Please Enter LastName")]
public string User_LN { get; set; }
[Required(ErrorMessage = "* Please Enter LoginID")]
public string User_Login { get; set; }
[Required(ErrorMessage = "* Please Enter PassWord")]
public string User_Password { get; set; }
[Required(ErrorMessage = "* Please Select a Valid Role")]
public int User_Role_ID { get; set; }
[Required(ErrorMessage = "* Please Select any one Table")]
public List<int> Table_ID { get; set; }
[Required]
public List<bool> P_Add { get; set; }
[Required]
public List<bool> P_Edit { get; set; }
[Required]
public List<bool> P_Delete { get; set; }
and i added this reference jquery files
<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
<script src="~/Scripts/jquery.validate.js"></script>
and set these keys to
<appSettings>
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
all the setting done but page still submitted...Please suggest me
You need to load validate.js before validate.unobtrusive.min.js