|
Ahh...i'm so stupid . I created a namespace "Help".
|
|
|
|
|
hi
i want to connect to Sqlserver 2000 from client (i done this step by create Login name as 'Guest'),but when i want to Create Database by Code,the following message shown me :
System.Data.SqlClient.SqlException: SELECT permission denied on object 'sysdatabases', database 'master', owner 'dbo'.
CREATE DATABASE permission denied in database 'master'.
...
where is the problem and how to solve it ?
|
|
|
|
|
Are you using SQL authentication (i.e. supplying a user name & password in the connection string)? If so, that user must have create rights in the SQL server instance. If you need help with that, I suggest asking in SQL forum[^].
|
|
|
|
|
You might be running into the problem creating the database with the Guest user. Guest should not have certain permissions to the database.
If you try to write that in English, I might be able to understand more than a fraction of it. - Guffa
|
|
|
|
|
Hi,
I'm having troubles closing my application with a Thread. Here is my code:
public partial class Form1 : Form
{
private Thread comReadThread;
private Boolean comReadThreadRunning;
private SerialPort comPort;
delegate void SetTextCallback(string text);
public Form1()
{
comReadThread = new Thread(new ThreadStart(this.comReadThreadProc));
comReadThreadRunning = true;
comPort = new SerialPort();
InitializeComponent();
comPort.PortName = "COM1";
comPort.ReadTimeout = 500;
comPort.WriteTimeout = 500;
comPort.BaudRate = 9600;
comPort.Open();
InitializeThreads();
}
private void InitializeThreads()
{
comReadThread.Start();
}
private void comReadThreadProc()
{
byte readByte;
StringBuilder readLine = new StringBuilder();
while (this.comReadThreadRunning)
{
try
{
readByte = (byte)this.comPort.ReadByte();
if (readByte != '\r')
{
readLine.Append((char)readByte);
}
else
{
String readString = readLine.ToString();
String[] splitStrings = readString.Split(new string[] {"°C"}, 5,StringSplitOptions.None);
if (splitStrings.Length > 0)
this.SetText(splitStrings[0]);
readLine = new StringBuilder();
}
}
catch (TimeoutException)
{
}
}
}
private void SetText(string text)
{
if (this.currentTempLabel.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.currentTempLabel.Invoke(d, new object[] { text });
Thread.Sleep(10);
}
else
{
this.currentTempLabel.Text = text;
}
}
private void button1_Click(object sender, EventArgs e)
{
comReadThreadRunning = false;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
comReadThreadRunning = false;
comReadThread.Join();
}
}
Closing the main form should set the boolean variable "comReadThreadRunning" to false, so that the while-loop in the thread-proc should quit. The "comReadThread.Join()" call causes my app to freeze then. Does anybody of you know why? I think it has something to do with my delegate for the UI updates.
Thanks for reading and best regards,
Rainer
-- modified at 18:25 Sunday 3rd December, 2006
|
|
|
|
|
comReadThread = new Thread(new ThreadStart(this.comReadThreadProc));
comReadThread.IsBackground = true;
|
|
|
|
|
Thank you for your quick post(!),
but that did not change anything ...
|
|
|
|
|
Try setting comReadThread to be a volatile variable:
volatile bool comReadThreadRunning;
|
|
|
|
|
Increasing the amount of waiting time at "Thread.Sleep()" solved my problem. I think, there where to many delegates:
private void SetText(string text)
{
if (this.currentTempLabel.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.currentTempLabel.Invoke(d, new object[] { text });
Thread.Sleep(500);
}
else
{
this.currentTempLabel.Text = text;
}
}
|
|
|
|
|
p.s. Instead of doing invokes from a background thread, have you looked at using System.ComponentModel.BackgroundWorker ? It's saved me quite a few headaches.
|
|
|
|
|
You're running into the classic deadlock problem. The Form1_FormClosing event is triggered on the UI thread through the message pump. You block execution of the event, waiting for comReadThread.Join . Imagine if at that point of time, comReadThreadProc reads a line and calls SetText . SetText then quite rightly calls Control.Invoke to marshal the call to the UI thread. But now the UI thread is hung waiting for comReadThread to complete and comReadThread will complete only if Invoke completes, which will only happen if the UI thread is free (i.e not waiting for Join). Clearly, that will not happen and you'll therefore deadlock.
The solution is to either remove the Join or use Control.BeginInvoke instead of Invoke . With BeginInvoke however, it's possible that the delegate will run after the form has closed, so you would have to take care of that condition.
|
|
|
|
|
hi,
I'm a totally new on c# and i wouldn't get this to work now, but I'm very curios if this could work and i could really need it.
I have a notebook with touchpad and when writing i always touch the pad.
because the notebook has no option to deactivate it by a key, i thought if its possible to write an application to do this.
i thought about something that filters all data that comes from the pad, i guess thats on some usb or com-port and leave that data to nowhere while the app is active.
is this possible?
would it work like i said or do you have to use another method?
aaaannnd
if its possible, would anyone be so kind to write me that lil app?
i thought about the app resting in the infopart of the taskbar and you simply left-click it.
one click to activate and another to deactive.
many thanks!
|
|
|
|
|
I think....
jiaoyamin
|
|
|
|
|
DarsVaeda wrote: I'm a totally new on c#
OK, in that case, you really should buy a basic book and work through it, before worrying about what real world apps you can create.
DarsVaeda wrote: is this possible?
I don't think it's likely. It's more likely if you have a decent notebook that you have a little button to turn that pad off manually. My notebooks sure have that.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian Graus wrote:
I don't think it's likely. It's more likely if you have a decent notebook that you have a little button to turn that pad off manually. My notebooks sure have that.
There may be an option to do the same via the control panel as well.
--
Rules of thumb should not be taken for the whole hand.
|
|
|
|
|
You can disable it, unloading the driver via control panel.
|
|
|
|
|
I have a large datatable which I have filled with parsed text data using C#, this table has one column containing alphabetic codes, all the other columns are numbers from 0 through to 10,000.
As a novice i was wondering how i convert the numeric columns to a different datatype such as "int" so i can then perform calculations, such as SUM on each column.However i need to leave the one colomn with the alphabetics as strings.
The datatable in question has approx 300 columns.
Some guidance on how to approach this would be greatly appreciated.
Thanks in advance
|
|
|
|
|
If your column is numbers, you should make it a numeric type. To convert a string to a number in C#, use int.TryParse.
int i;
if (int.TryParse("3244", out i))
{
// TryParse returns true if the string could be converted.
}
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Thanks christian
Excuse my lack of experience with this Christian but how do I apply this to all the values in my datatable.
I also forgot to say that all of the columns have a header row that has to remain as a string, so i guess what i have to do is cycle through all the individual cells in the datatable and convert the ones that can be converted with TryParse, is this correct ? and if so how would i approach this.
thanks again
|
|
|
|
|
minnie mouse,
To convert every string in your database to an int you must iterate thru every row and change the value in each column to a int.
For example if you have grabbed all data from your database and have filled your dataset with this data. Use the code below check for syntax errors.
But this should get you going.
DataTable table = MyDataSet.Tables[0];
foreach(DataRow row in table.Rows)
{
foreach(DataColumn column in table.Columns)
{
int newIntValue = int.Parse(row[column].toString());
row[column] = newIntValue;
}
}
In your database you must be sure to change the dataType of the column so that when you update your database with the dataset via dataAdapter you get no dataType errors.
|
|
|
|
|
Thanks for this help, please see Christians comments
Much clearer now.
|
|
|
|
|
minnie mouse wrote: Excuse my lack of experience with this Christian but how do I apply this to all the values in my datatable.
Your core problem is that your database design is wrong. As it stands, you need to create a new column in your datatable, and copy the values across using SQL. Then delete the old table. I'm not sure that you can just change the type of a column.
minnie mouse wrote: I also forgot to say that all of the columns have a header row that has to remain as a string,
Is this a database we're talking about ? A header is obvioulsy a string. It's the name of the column.
minnie mouse wrote: so i guess what i have to do is cycle through all the individual cells in the datatable and convert the ones that can be converted with TryParse, is this correct ?
To do this in memory, and keep your database in this less than useful format, yes. I think someone else gave you some sample code.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian,
Thanks for your help with this, all the info I have read so far doesnt seem to apply to the situation I have. Which is the need to write a data import programme, therefore the approach most of the educational material i have seen of firstly design the database, then etc , etc cant be applied as i'm starting with nothing but a large amount of csv data.
Ive got to the point where i can succesfully store all this as string data in a SQL database tables. I now need to perform some calculations on the majority of the columns.These columns contain numbers but have names as the first row. I wasnt sure if it was easier to conert to numeric datatype first or try to act on the stored strings in the table with maybe a stored procedure?
Please excuse my lack of understanding of this, i am looking for experienced guidance.
|
|
|
|
|
If you're starting with a CSV, then rewrite your import code to create numeric columns for numeric data. Otherwise, you'll always be held back by poor database design.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Thanks christian
I will now do that. I did wonder at the time if I was going the right way.
Stay tuned for future developments !
Curvoisier concerto is a personal favourite of mine.;)
|
|
|
|