|
That's basically the way the underlying Win32 function works.
One common approach is to try to open the file - it will be there and accessible when you can open it.
|
|
|
|
|
Can anyone help me understand why this connection string is not working. I have the following piece of code
string connString = "user id=sa;password=;initial catalog=dbName;data source=Test;Connect Timeout=30";
SqlConnection connect = new SqlConnection(connString);
try
{
connect.Open();
.....}
catch
{
...
}
It gives me the error "SQL server does not exist or access denied." The datasource is correct and tests out correctly in the ODBC administrator. It does not matter what database name I put in there. Another interresting thing, If I change the connection string and eliminate the data source completely it give me the error
"Login failed for user "sa" Not associated with a trusted SQL server connection" I have used the ODBC connection and database in my C++ application and they work just fine. Any ideas why C# is causing me such a headache? Thanks for any help.
|
|
|
|
|
I believe the SqlConnection object is not an ODBC object, but a native SQL Server connection. So your data source needs to be the IP Address of your server or the DNS server name, rather than an ODBC data source name.
Ron Ward
|
|
|
|
|
Try ODBC.NET[^] and a connection string like "DSN=Test;".
Paul
Pleasently caving in, I come undone - Queens of the Stone Age, No One Knows
|
|
|
|
|
- Check that the server "Test" is running, and that you can see it from your machine;
- Check that the server is set to allow SQL Server authentication - the default settings only allow Windows authentication;
- If your server is set to Windows authentication, change the connection to:
initial catalog=dbName;data source=Test;Connect Timeout=30;Integrated Security=True; - If the server allows SQL authentication, check the password for sa - if it really is blank, you should set it immediately!
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
|
|
|
scroll down to the heading Keystroke Message Flags. thats what i need. i am using KeyboardProc for a windows hook, and i need to get the information returned in the lParam. only problem is, i cant understand how to turn that IntPtr into a structure so i can get the info.
1001111111011101111100111100101011110011110100101110010011010010 Sonork | 100.21142 | TheEclypse
|
|
|
|
|
|
thanks - but how exactly would i check the value of a bit?
1001111111011101111100111100101011110011110100101110010011010010 Sonork | 100.21142 | TheEclypse
|
|
|
|
|
|
Understanding how to use bitshifts, etc to me seems to be something you either get or you don't. I'll do my best to try to explain it.
In most case you're referring to a 32-bit integer, I lay them out in my head like so
(31) -------- -------- -------- -------- (0)
bit 0 is on the right, and bit 31 on the left.
Bitwise operators work by using a truth table to get the result of doing an operation on two bits.
And (&) | 0 | 1 | Or (|) | 0 | 1 | XOr (^) | 0 | 1 |
--------|---|---| -------|---|---| --------|---|---|
0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 |
--------|---|---| -------|---|---| --------|---|---|
1 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | Now that we have the truth tables we can almost begin to construct equations to use them.
To use them we need to figure out what values we need to use in order to get the appropriate values out.
ex. We want to check bit 15 of some 32-bit integer.
To check certain bits you want to isolate them, so the easiest way to accomplish this is to AND the value with a mask so that only the value of bit 15 comes out in the end.
Looking at the truth table for AND above, we see that anything ANDed with 0 results in zero, but if you AND something with 1 you get the orignal value out. BINGO!
So, our mask looks like:
(31) 00000000 00000000 10000000 00000000 (0)
if you AND the above with any value, you'll get out the value of bit 15.
This mask is easily generated, its simply (1 << 15) (1 shifted 15 places to the left, (1 << 3) is 00001000, 1 shifted 3 places to the left).
Typically you'll see the bitmasks as flags in an enum (or when doing interop as #define's). The values will often be represented in hex, because its generally easier to do some of these in your head.
Counting in hex... 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100, 0x0200... Those are the values from bit 0 to bit 9.
Now lets say that bits 8 through 23 represent something and you want that value.
First, you need to mask out bits 0-7 and 24-31:
The mask is simple
(31) 00000000 11111111 11111111 00000000 (0)
Now convert each section of 8 bits to hex, and we get 0x00FFFF00
Now AND the original value with the mask.
int val = (original & 0x00FFFF00);
You can't use the original value as-is, its still too large because you still have some extra numbers at the end! To sovle that problem, SHIFT the value to the right however many bits you need. In this case, 15 bits to the right.
val = (val >> 15);
Now val contains the numeric value contained in bits 8-23 of the original value.
Sometimes you need to OR (|) two values together to create a mask, typically you do this when you are only interesting in whether one or more of those bits are set, not WHICH of those bits is set.
ex. If bit 2 is set, then a key has been pressed and released.
If bit 3 is set, then a key is being held down.
Determine if a key has been pressed.
First generate the two masks we need
(7) 00000010 (0) - bit 2
(7) 00000100 (0) - bit 3
Now OR them together to get the mask to tell you if either of the bits are set.
(7) 00000110 (0) - bits 2 and 3
Now you can AND this with the original value. Since together they have no meaning, you just want to compare whether the ANDed value is non-zero.
bool isKeyPressed = ((original & 0x06) != 0);
This only tells you if EITHER bit 2 OR bit 3 is set, not which of the two are set.
Hope that helps a bit,
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
|
Actually, in the second example when you wanted bits 8-23, you shouldn't right-shift 15 bits, only 8 bits. I'm sure James was probably just thinking about his previous example. Good explanation though James.
"Well, I wouldn't say I've been missing it, Bob." - Peter Gibbons
|
|
|
|
|
|
Oh, I know it was only a typo. I just wanted to point out to Nnamdi (the original poster) that there was a typo so he wouldn't get confused (perhaps).
"Well, I wouldn't say I've been missing it, Bob." - Peter Gibbons
|
|
|
|
|
I got the following error while executing the installutil/u MyFile.exe. Refer the steps below:
---------------------------------------------------------------------------------------------------------------------------
Affected parameters are:
assemblypath = d:\test\filewatcher.exe
logfile = d:\test\filewatcher.InstallLog
An exception occurred during the uninstallation of the FileWatcher.SetupInstaller installer.
System.NullReferenceException: Object reference not set to an instance of an object.
An exception occurred while uninstalling. This exception will be ignored and the uninstall will continue. However, the application might not be
fully uninstalled after the uninstall is complete.
Removing EventLog source OFACFolderWatchService.
Service OFACFolderWatchService is being removed from the system...
Service OFACFolderWatchService was successfully removed from the system.
----------------------------------------------------------------------------------------------------------------------------------
Detailed Steps:
=========
I developed FileWatcher windows service using C# and created Microsoft Installer. Installation and Uninstallation was working fine.
Later I customized the Microsoft Installer by adding one Installer class (SetupInstaller.cs) to my existing FileWatcher project.
Added the Override method of base Class as:
public override void Install(System.Collections.IDictionary PassData)
{
//update the XML File
string strAppPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
strAppPath = strAppPath.Substring(0,strAppPath.LastIndexOf("\\")+1);
string strXMLFile = strAppPath + "OFACTracker.xml";
XmlDocument objXMLDocument = new XmlDocument();
string strNodeValue = "";
try
{
objXMLDocument.Load(strXMLFile);
XmlNodeList objNodeList = objXMLDocument.GetElementsByTagName("InBox");
strNodeValue = strAppPath + "Inbox";
objNodeList.Item(0).FirstChild.Value = strNodeValue;
objXMLDocument.Save(strXMLFile);
}
catch(Exception)
{
//Exception Handling
}
}
Note:
ProjectInstaller.cs already exist while creating the service. I didnt touch this installer class.
Created Setup Package. Here I added Project group to an Application Folder of System Editor and Added custom Action to an Install Node.
In this case Installation was working file (Service registered automatically). Before Unstallation, executed Installutil/u FileWatcher.exe and got the above
error.
Thanks in Advance
Karthik
|
|
|
|
|
Did you read this article[^] ?
It says "Remove the service. When you're done, use the Services dialog box to stop your service. Run InstallUtil with its /u parameter to uninstall your service. You'll also need to shut down the Windows Services applet to completely remove your service from memory.".
|
|
|
|
|
Yes it's working fine in development enviroment. Created the Microsoft Installer for Windows service by referring the link :
http://www.msdn.microsoft.com/library/en-us/dndba/html/DALGIssues.asp (Page# 12 to 14).
The problem is in Microsoft Installer. I run the setup package in the same development. Installation is working fine and installed the service automatically without using installutil feature. Before uninstalling using Add/ Remove program, Stopped the service, executed installutil/u and closed the Windows Service applet. And removed the application using Add/Remove program.
Later I customized the installation by adding one installer class. Pl refer the override method "Install" which I submitted in the previous mail. Created Microsoft installer and executed the setup in the same machine and service installed successfully.
Before uninstalling using Add/ Remove program, Stopped the service, executed installutil/u and got the error.
Thanks In Advance
Karthik
|
|
|
|
|
Nice work Rod, you've answered all queries on the frontpage of this forum keep it up...
May the Source be with you
Sonork ID 100.9997 sijinjoseph
|
|
|
|
|
thank Rod answered my questions
from fretre
|
|
|
|
|
Hello,
I need to write code to insert a user selected picture into a RichTextBox.
After checking the RTF file generated by WordPad, I found I can use the
following code to add a picture into RichTextBox:
string text = "";
text +=
"{\\rtf1\\ansi\\ansicpg936\\deff0\\deflang1033\\deflangfe2052{\\fonttbl{\\f0
\\fnil\\fcharset0 Microsoft Sans Serif;}}\n";
text +=
"\\uc1\\pard\\lang2052\\f0\\fs17{\\pict\\wmetafile8\\picwgoal480\\pichgoal24
0\n";
text += "............."; // data here
text += "\n}}";
richTextBox1.SelectedRtf = text;
But, I still do not know how to encodethe data field automatically.
Currently I can only paste it from the WordPad generated RTF.
Is there some easier way to let user select a bitmap file(bmp, jpg, etc.),
then insert it to the RichTextBox control?
Thank you very much,
weixiang
|
|
|
|
|
I personally would rely on the clipboard, ie load the image into the clipboard and use the RichTextBox.Paste(Format frmt) method to produce the stream.
This stream can then be saved to disk for reuse with RichTextBox.SaveFile(path) .
|
|
|
|
|
That's a good method. Thank you, .S.Rod
|
|
|
|