SQL Server CE database upgrade 3.5 to 4.0 C# - c#

I'm totally new. I'm following a book and teaching my self C#. I'm reading one of the HEAD FIRST books. I just created a contact data base program. I made the SQL database placed it on a form did all the steps. And when I go to run the program I get this view source print?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void pictureBox1_Click(object sender, EventArgs e) {
MessageBox.Show("Contact List 1.0. \nWritten by: Greg Amero", "About");
}
private void peopleBindingNavigatorSaveItem_Click(object sender, EventArgs e) {
this.Validate();
this.peopleBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.contactDBDataSet);
}
private void Form1_Load(object sender, EventArgs e) {
// TODO: This line of code loads data into the 'contactDBDataSet.People' table. You can move, or remove it, as needed.
this.peopleTableAdapter.Fill(this.contactDBDataSet.People);
}
}
}
At the this.peopleTableAdapter.Fill(this.contactDBDataSet.People); I get an error msg saying
SqlCelnvaliddatabase format exception was unhandled.
The database file has been created by an earlier version of SQL Server Compact. Please upgrade using SqlCeEngine.Upgrade() method.
I get the above error using visual 2010
If I use Visual 2012 express it works fine and I'm thinking it has something to do with the SQL Server CE versions they run off of. I've installed SQL Server CE 3.5, 4.0 , etc but still not work.. Please help..
Greg

Use following code to upgrade SQL Server Compact version 3.5 files to 4.0.
public static void Upgrade(string fileName, string password)
{
if (String.IsNullOrEmpty(fileName) || password == null)
throw new Exception("Unable to create connection string because filename or password was not defined");
try
{
var connectionString = string.Format(#"Data source={0};Password={1}", fileName, password);
var engine = new SqlCeEngine(connectionString);
engine.Upgrade();
}
catch (Exception ex)
{
throw (ex);
}
}

Related

how to connect(call) wcf service on xamarin android?

i have 2 project on my solution
1 android
2 wcf service application
i created a service to add my data on my database
database info:
sql server 2014
i tested my service on debug and work fine
info:
connect via liq
and , add to my android project by add reference
service added successfully
i can see my tables , fields and ...
when i create an instance of my table on click method of my project
android project run success but not affect on my database
i point a break point on codes and see data to be add but no affect
here is my codes
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
namespace Siman_Android
{
[Activity(Label = "PersonAddActivity")]
public class PersonAddActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
Button btn = FindViewById<Button>(Resource.Id.btnadd);
btn.Click += Btn_Click;
}
ServiceRefrence.Service1 myService = new ServiceRefrence.Service1();
private void Btn_Click(object sender, EventArgs e)
{
myService.Url=("http://localhost:13294/Service1.svc");
EditText txtname = FindViewById<EditText>(Resource.Id.txtname);
EditText txtfamily = FindViewById<EditText>(Resource.Id.txtfamily);
myService.GetPersonAsync(txtname.Text, txtfamily.Text);
}
}
}
and my service code to add person
public bool GetPerson(string FirstName, string LastName)
{
try
{
PersonName pr = new PersonName()
{
Family = LastName,
Name = FirstName
};
db.PersonNames.Add(pr);
db.SaveChanges();
return true;
}
catch (Exception)
{
return false;
}
}
please help!
You can use local network IP address from your PC if your emulator is on the same network. Also check if your VM has networks from Oracle box. That might create problems

fileupload control causing server error

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
String fn = FileUpload1.FileName;
string fp = Server.MapPath("images");
if (fp.EndsWith("\\") == false)
{
fp = fp + "\\";
}
fp = fp + fn;
FileUpload1.PostedFile.SaveAs(fp);
}
}
on runnning this code, i receive the following error:
Server Error in '/WebSite11' Application
HTTP Error 400 - Bad Request.
Version Information:
ASP.NET Development Server 10.0.0.0
If the images folder is located at the root of your site then path should be this
string fp = Server.MapPath(~"/images");
and also try to run the site on a different brwose bcz few days ago i saw the same issue but when he rans the code on a different browse it works fine.
see the following post
HTTP Error 400 - Bad Request due to FileUpload control in vb.net

Crystal Reports C#

I have a multitable c# report based on a database I have created underneath using SQL. I am using the following code to try and set the datasource and have tried many different variations but cannot get the information from my database to show up properly in my report. Any help is greatly appreciated. The dataset is populating. Additionally the single table reports properly fill with data only the multitable reports aren't working.
UPDATE: The report now shows data from one table using report.Database.Tables["Invoices"].setDataSource(posDataSet.Tables["Invoices"]); However using the same logic on the table that generates the detail lines does not show any data.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
namespace SureSalePos
{
public partial class Reporter : Form
{
private PosDatabaseDataSet posDataSet;
public Reporter(PosDatabaseDataSet dataToReportOn)
{
InitializeComponent();
posDataSet = dataToReportOn;
//InvoiceReport ir = new InvoiceReport();
// this.reportViewer.LocalReport.ReportPath = ir.FileName;
}
private void Reporter_Load(object sender, EventArgs e)
{
ConnectionInfo myConnectionInfo = new ConnectionInfo();
myConnectionInfo.ServerName = "";// "PosDatabaseDataSet";
myConnectionInfo.DatabaseName = "";//"PosDatabase.mdf";
myConnectionInfo.UserID = string.Empty;
myConnectionInfo.Password = string.Empty;
setDBLOGONforREPORT(myConnectionInfo);
//this.reportViewer.RefreshReport();
}
private void setDBLOGONforREPORT(ConnectionInfo myconnectioninfo)
{
InvoiceReport report = new InvoiceReport();
report.DataSourceConnections.Clear();
// For each table set the source from your dataset
report.Database.Tables["Invoices"].SetDataSource(posDataSet.Tables["Invoices"]);
report.Database.Tables["InvoiceItems"].SetDataSource(posDataSet.Tables["InvoiceItems"]);
//report.Database.Tables["People"].SetDataSource(posDataSet.Tables["People"]);
report.Database.Tables["Preferences"].SetDataSource(posDataSet.Tables["Preferences"]);
//report.Database.Tables["Skus"].SetDataSource(posDataSet.Tables["Skus"]);
crystalReportViewer1.ReportSource = report;
crystalReportViewer1.RefreshReport();
}
private void crystalReportViewer1_Load(object sender, EventArgs e)
{
}
}
}
EDIT: Updated Code above September 22
You shouldn't need to set the login since you are supplying the report data. Try the following:
report.DataSourceConnections.Clear();
// For each table set the source from your dataset
report.Database.Tables["TableName"].SetDataSource(posDataSet.Tables["TableName"]);
crystalReportViewer1.ReportSource = report;
crystalReportViewer1.RefreshReport();

C#: execute a function stored in a string variable

Is it possible to write a simple and fast function in C# that will execute arbitrary methods from a string? For example, if I set MyString="MessageBox.Show("Some Message")" and then call ExecuteString(MyString), a message box would pop up with "Some Message" in it.
(I've probably made some sort of error in the above code. I don't yet know C#; I'm trying to evaluate whether it would be appropriate for a specific project.)
You should be able to use this and wrap the code required to run a string into a function.
Essentially what you're doing is wrapping the small bit of C# code in a Program.Mainstyle function, referencing some assemblies for basic functionality (maybe including your own assembly) then run the compiled program in memory.
It's likely a bit of more overhead than you need to simply run one or two lines of code mind you.
http://support.microsoft.com/kb/304655
what you appear to be looking for is CS-Script
Alas, C# is not a dynamic language in that way. You can't really do this easily, and if it's really something you need to do, consider using a .Net language more in line with your needs, like IronPython or IronRuby.
Your best available alternative is to use the CodeDom namespace, as this truly convoluted and heinous example from this forum thread shows:
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using System.Windows.Forms;
namespace TestApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SampleLib.SampleType test = new SampleLib.SampleType();
private void button1_Click(object sender, EventArgs e)
{
// Dynamically build and call the method
label1.Text = test.MyText;
}
private void button2_Click(object sender, EventArgs e)
{
StringBuilder DynamicCode = new StringBuilder();
DynamicCode.Append("namespace TestDynamic");
DynamicCode.Append("{");
DynamicCode.Append("public class DynamicCode");
DynamicCode.Append("{");
DynamicCode.Append("public static void EditText(SampleLib.SampleType t)");
DynamicCode.Append("{");
DynamicCode.Append("t.MyText = \"Goodbye!\";");
DynamicCode.Append("}");
DynamicCode.Append("}");
DynamicCode.Append("}");
string CodeString = DynamicCode.ToString();
System.IO.FileInfo fi = new System.IO.FileInfo(Application.ExecutablePath);
CodeDomProvider provider = CodeDomProvider.CreateProvider("C#");
CompilerParameters CompileParams = new CompilerParameters(new string[] { fi.DirectoryName + "\\SampleLib.dll" },
fi.DirectoryName + "\\Dynamic.dll");
CompileParams.MainClass = "DynamicCode";
CompileParams.GenerateExecutable = false;
//CompileParams.GenerateInMemory = true;
CompilerResults r = provider.CompileAssemblyFromSource(CompileParams, new string[] {CodeString});
foreach (CompilerError er in r.Errors)
{
Console.WriteLine(er.ErrorText);
}
}
private void button3_Click(object sender, EventArgs e)
{
// Dynamically call assembly
System.IO.FileInfo fi = new System.IO.FileInfo(Application.ExecutablePath);
Assembly dynAsm = Assembly.LoadFile(fi.DirectoryName + "\\Dynamic.dll");
if (dynAsm != null)
{
object o = dynAsm.CreateInstance("TestDynamic.DynamicCode", true);
Type t = dynAsm.GetType("TestDynamic.DynamicCode");
t.GetMethod("EditText").Invoke(o, new object[]{test});
}
}
}
}

SharpPcap issue

This is my first time to use SharpPcap library.
I created new project with VC# 2008 and I added SharpPcap as a reference to my project.
I post a sample code to get interface of my pc but I'm getting this error:
Error 1 The type or namespace name 'PcapDeviceList' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Ali\Documents\Visual Studio 2008\Projects\Pcap\Pcap\Form1.cs 28 13 Pcap
please advice to solve this problem.
here is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SharpPcap;
using SharpPcap.Packets;
using SharpPcap.Protocols;
using SharpPcap.Util;
namespace Pcap
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
/* Retrieve the device list */
PcapDeviceList devices = SharpPcap.GetAllDevices();
/*If no device exists, print error */
if (devices.Count < 1)
{
Console.WriteLine("No device found on this machine");
return;
}
int i = 0;
/* Scan the list printing every entry */
foreach (PcapDevice dev in devices)
{
/* Description */
label1.Text = "{0}) {1}" + i + dev.PcapDescription +"\n"+
/* Name */
"\tName:\t{0}" + dev.PcapName+"\n"+
/* IP Address */
"\tIP Address: \t\t{0}"+ dev.PcapIpAddress+"\n"+
/* Is Loopback */
"\tLoopback: \t\t{0}"+ dev.PcapLoopback;
i++;
}
}
}
}
What version of SharpPcap are you using?
I'm moving a small in-work project from 2.1.1 to 2.4.1, and parts of the library have changed significantly. I struggled with this myself just a bit ago.
LivePcapDeviceList devices = LivePcapDeviceList.Instance;
foreach (LivePcapDevice device in devices)
{
// Do stuff here...
}
Sorry about the API changes. I'm still trying to get the API named properly. As of v3.0 the API is considerably cleaner and should be a bit more static going forward. If you have any trouble post on the devel list or sf forums and you'll get a quick reply.
Chris
SharpPcap maintainer/author
http://sharppcap.sf.net
Try using Pcap.Net. It's a clear WinPcap wrapper in .NET.

Categories