|
Do you ever close the connection?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
Only when I close the program. Why?
|
|
|
|
|
Because the normal way to do things is:
1) Open connection
2) Do transaction
3) Close connection
This reduces the connections to a database and the load on the system.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
After I removed the line you told me to, and added fs.close() I've got a new exception:
Unrecognized database format 'file name.accdb'.
I do have the file created.
|
|
|
|
|
That's a good start! The problem now, is probably that the file is empty. So when Access tries to use it, it expects it to be a valid (if blank) Access DB.
Probably the easiest way is to:
1) Manually prepare a blank database (set up your tables and so forth, but do not add any data: call it "MyBlankDB.accdb") and add it to your project.
2) Set it's properties to "embedded resource"
3) Use this to create your file:
System.Reflection.Assembly objAssembly = System.Reflection.Assembly.GetExecutingAssembly();
using (Stream blankDBData = objAssembly.GetManifestResourceStream("MyBlankDB.accdb"))
{
byte[] data = new Byte[blankDBData.Length];
blankDBData.Read(data, 0, (int) blankDBData.Length);
blankDBData.Close();
using (FileStream newDBFile = new FileStream(pathToWhereIWantToPutTheDatabase, FileMode.Create))
{
newDBFile.Write(data, 0, (int) blankDBData.Length);
newDBFile.Close();
}
}
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
Marat Beiner wrote: I wont to create for every user his private data base
..and how many users are you expecting?
Marat Beiner wrote: I create an accdb file for him, connect to this data base and create tables
..and why did you choose Access over Sql Express?
I are Troll
|
|
|
|
|
Amongst the things that others have mentioned your main problem is that the file you create is not an Access Database file.
The suggestion that you have an empty database file and copy it then rename it (from OriginalGriff, I think) will work but you can actually create an access database file programmatically, if you want to.
Here's how.
1) Create a new Windows Forms project. (Call it CreateAccessACCDB, or whatever takes your fancy)
2) Add two TextBoxes and one Button . In order to match the code below name the TextBoxes txtDbName and txtDBPath , otherwise modify the code to match what you name them.
3) Add a reference to the project. Select the 'Com' tab, in the References Dialog, and scroll down till you find 'Microsoft ADO Ext. 2.8 for DDL and Security' and add a reference to it. If you don't find it on your system, you will have to download and install it from Microsoft[^].
4) Double-Click the Button and add the code below into the blank handler that you get.
if (File.Exists(this.txtDBPath.Text + this.txtDbName.Text + ".accdb"))
{
File.Delete(this.txtDBPath.Text + this.txtDbName.Text + ".accdb");
}
Catalog cat = new Catalog();
try
{
string creationString = "Provider=Microsoft.ACE.OLEDB.12.0;" +
" Data Source=" + this.txtDBPath.Text + this.txtDbName.Text + ".accdb";
cat.Create(creationString);
MessageBox.Show("Database Created Successfully");
}
catch (Exception ex)
{
MessageBox.Show("Oh deary, deary me." + Environment.NewLine + ex.ToString(), "Oooops");
return;
}
cat = null;
OleDbConnectionStringBuilder connBuilder = new OleDbConnectionStringBuilder();
connBuilder.DataSource = this.txtDBPath.Text + this.txtDbName.Text + ".accdb";
connBuilder.Provider = "Microsoft.ACE.OLEDB.12.0";
OleDbConnection tablesConn = new OleDbConnection(connBuilder.ConnectionString);
this.CreateTables(tablesConn);
Note that the code uses the run-time driver for Access 2010. If you don't have it, download and install it from Microsoft[^], or edit the code to use the version that you have.
All you have to do then is run it, enter a path into the path box (make sure it ends with a '\') and the name you want for the database (without the '.accdb' extension) in the name textbox, then click the button.
An example of a simple CreateTables() method
private void CreateTables(OleDbConnection conn)
{
string tableSql = @"CREATE TABLE FoodTable(FoodID SHORT NOT NULL , FoodName VARCHAR(30) NOT NULL , FoodType VARCHAR(15) NOT NULL , FoodPrice CURRENCY NOT NULL )";
OleDbCommand tableCommand = new OleDbCommand(tableSql, conn);
conn.Open();
tableCommand.ExecuteNonQuery();
conn.Close();
}
this is cut down a bit, as in my app I use a table definition file which allows for Primary Keys and Indexes etc., but you can look up the syntax for that on MSDN or elsewhere.
This was tested on a machine running XP, so if you are on Vista or Windows 7 you might get security errors. I cannot help with those. Also this was done for just goofing around so there is very little error checking.
Hope it helps.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
I wouldn't let CG touch my Abacus!
When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is.
|
|
|
|
|
Thanks to everybody I've sold it, by creating static database, and then every time I create new one by System.IO.Copy, in other words I copy a static one to new one.
|
|
|
|
|
Well done.
Could you edit your original question to mark it 'Solved'. When you click the 'edit' widget under your question you will see "[Modified]" in the subject line. Simply replace the 'Modified' with 'SOLVED'.
That way people will know that you no longer need help.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
I wouldn't let CG touch my Abacus!
When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is.
|
|
|
|
|
I am implementing Unity in a business app for the first time.
Here is some sample code to implement logging DI with Unity:
UnityContainer uc = new UnityContainer();<br />
uc.RegisterType<ILogger, FileLogger>();<br />
ILogger logger = uc.Resolve<ILogger>();<br />
<br />
logger.Write();
One way to implement this in an app would be to put this code in an AppConfig.cs class and implement GetLogger as a singleton.
What's your preferred way to implement Unity in this scenario?
|
|
|
|
|
I think Singleton is best way of implementing. Why would you choose other way? any specific requirements? 
|
|
|
|
|
Ok - so to implement this as a singleton how would you envision the solution structure?
For example, would you see a singleton class in its own class library with a namespace like:
"MyCompany.MyDivision.MyApp.DI"? With the singleton class named something like "DIManager"?
Then I suppose that every library that needed the DI info would need to add a reference to the custom DI class library? Is this correct?
|
|
|
|
|
hello
i am reading a Wrox.Beginning.Microsoft.Visual.C.Sharp.2008 and i have question from exercises and it says
Create a delegate and use it to impersonate the Console.ReadLine() function when asking for
user input.
i am not sure i get the idea so please let me know
thank you
Gilberto
|
|
|
|
|
All it means is to create a delegate which allows you to call a method (in this case Console.ReadLine) without using that name.
delegate string MyMethodDelegate();
static void MyMethod()
{
MyMethodDelegate readALineFromUser = new MyMethodDelegate(Console.ReadLine);
Console.WriteLine("Enter your name:");
string inp = readALineFromUser();
Console.WriteLine("Your name is\"{0}\". ", inp);
}
Why would we use it?
Because we could change the input source from Console.ReadLine to MyBatchFileReadLine at run time without changing any of the code that uses readALineFromUser:
delegate string MyMethodDelegate();
static void MyMethod()
{
MyMethodDelegate readALineFromUser = new MyMethodDelegate(MyBatchFileReadLine);
Console.WriteLine("Enter your name:");
string inp = readALineFromUser();
Console.WriteLine("Your name is\"{0}\". ", inp);
}
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
thank you soo much OriginalGriff i now get the idea
but MyBatchFileReadLine i don't think that i came to that level for now ,so if you don't mind tell me what its story ?? ^_^
thank you again

|
|
|
|
|
"MyBatchFileReadLine" doesn't exist: I used it as an example of a potentially different input source - a batch file of names instead of the user typing each one directly.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
One of the best and most concise explanations of delegates that I've seen.
I must get a clever new signature for 2011.
|
|
|
|
|
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
10000 X thankes

|
|
|
|
|
You are welcome!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
Good afternoon,
I am using pdf clown library to extract the pdf contents.Now i want to extract the whole table content from pdf.
|
|
|
|
|
When you use a 3rd-party library, your best source of information is always the forum of the product.In this case it's here[^].
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
I wouldn't let CG touch my Abacus!
When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is.
|
|
|
|
|
I got this Link[^] having same question with solution.
you can try using pdfsharp managed assembly. go there[^] to take a look.
I hope it might help you
|
|
|
|
|
Hello Experts,
I have a code of Keyboard Hook In which have a problem when i m tring to Capture Unicode Character then it's not working fine.
I know that i want to use MapVirtualKeyEx, ToUnicodeEx function to convert for Unicode.
But i am not unable to understand this function .
So Please can any one help me to convert it function for Unicode Support.
Private Function KeyboardProc(ByVal nCode As Integer, ByVal wParam As IntPtr, ByRef lParam As KeyboardData) As IntPtr
If (nCode >= NativeMethods.HC_ACTION) Then
Dim e As Pcdll.KeyBoardEventArgs
Dim keyCode As Keys = CType(lParam.vkCode, Keys)
Select Case True
Case CInt(wParam) = NativeMethods.WM_KEYDOWN Or CInt(wParam) = NativeMethods.WM_SYSKEYDOWN
If keyCode = Keys.LMenu Or keyCode = Keys.RMenu Then
Me._keyData = Me._keyData Or Keys.Alt
e = New Pcdll.KeyBoardEventArgs(Me._keyData Or Keys.Menu, keyCode)
ElseIf keyCode = Keys.LControlKey Or keyCode = Keys.RControlKey Then
Me._keyData = Me._keyData Or Keys.Control
e = New Pcdll.KeyBoardEventArgs(Me._keyData Or Keys.ControlKey, keyCode)
ElseIf keyCode = Keys.LShiftKey Or keyCode = Keys.RShiftKey Then
Me._keyData = Me._keyData Or Keys.Shift
e = New Pcdll.KeyBoardEventArgs(Me._keyData Or Keys.ShiftKey, keyCode)
Else
e = New Pcdll.KeyBoardEventArgs(Me._keyData Or keyCode, keyCode)
End If
Me.OnKeyDown(e)
If e.Handled Then
Return CType(1, IntPtr)
End If
Case CInt(wParam) = NativeMethods.WM_KEYUP Or CInt(wParam) = NativeMethods.WM_SYSKEYUP
If keyCode = Keys.LMenu Or keyCode = Keys.RMenu Then
Me._keyData = Me._keyData And Not (Keys.Alt)
e = New Pcdll.KeyBoardEventArgs(Me._keyData Or Keys.Menu, keyCode)
ElseIf keyCode = Keys.LControlKey Or keyCode = Keys.RControlKey Then
Me._keyData = Me._keyData And Not (Keys.Control)
e = New Pcdll.KeyBoardEventArgs(Me._keyData Or Keys.ControlKey, keyCode)
ElseIf keyCode = Keys.LShiftKey Or keyCode = Keys.RShiftKey Then
Me._keyData = Me._keyData And Not (Keys.Shift)
e = New Pcdll.KeyBoardEventArgs(Me._keyData Or Keys.ShiftKey, keyCode)
Else
e = New Pcdll.KeyBoardEventArgs(Me._keyData Or keyCode, keyCode)
End If
Me.OnKeyUp(e)
If e.Handled Then
Return CType(1, IntPtr)
End If
End Select
End If
Return NativeMethods.CallNextHookEx(Me._hKeyboardHook, nCode, wParam, lParam)
End Function
Reqired Link is here :
Global Windows Hooks[^]
Thanks
If you can think then I Can.
|
|
|
|
|
This code does not look much like C# to me. Try posting in the correct forum.
I must get a clever new signature for 2011.
|
|
|
|