|
I found a solution. Basically, the Jet Engine seems to have problems with translation. To get the correct data, I have to do this:
SELECT * FROM TABLE WHERE Date BETWEEN Format(#" + startDate + "#,'mm/dd/yyyy')AND Format(#" + endDate + "#,'mm/dd/yyyy')
By setting the format in the SQL statement to United States format, the data seems to come back to me correctly.
|
|
|
|
|
If I have a text file containing the first line like this:
John 1976 200,000 United States
How do I import it to the database specifying that the first column should be John, second is 1976, third is 200,000, and last column is United States?
What are the commands/syntax being used to achieve this? Thanks.
|
|
|
|
|
Your text file format is a disaster. So long as country is the only field that can have a space in it, you may be OK. You use the string.Split method to turn this into a string array. If there's a fifth or sixth element, you append those to the fourth ( that's the country ). Then you have values to stuff into the database.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks. How do we use bcp or bulk insert to import the data in text file into the database? I haven't done anything with databases or ADO.Net so I might need some step by step procedure to do this.
|
|
|
|
|
In that case, I'd recommend going through an article on the topic, on this site or elsewhere. It's just going to cover things in far more depth and clarity than I can hope to do in a forum reply.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I answered a question a few posts ago, where a user thought that assigning reference types was creating aliases for the names of those types. After thinking about it, I began to wonder if there IS a way to do this, so that you have two instances referencing the same pointer to the object. For example, is there a way to do the following in C# (I doubt it, because it was often the cause of many problems in C++, but just thought I would ask)?
object A = new object();
object B = ref A;
B = new object();
Hope this question makes sense. Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Hi Jeff,
I have never seen such thing, so AFAIK it is impossible.
Also, IMO the C# language designers would consider it unnecessary and unsafe.
And if you look at pointers, they can only point to value types.
So I think you will have to refactor the code and substitute every B by A.
[added]
the feature you're asking about is similar to the union in C/C++;
it is not supported in C#, although there is a way to mimic it inside structs,
by giving explicit FieldOffset values
I use unions (in C that is) only to byte-convert from one type to another, not to get two names for
the same thing; sometimes I miss it in C#. Not sure how the C# compiler would cope with the latter.
[/added]
modified on Tuesday, December 11, 2007 2:49:59 PM
|
|
|
|
|
Yeah, I remembered doing it in C++ before, but couldn't remember what the keyword was. I don't really have a need (nor see a need) to do this, since, as you said, I could just substitute the variable A for all occurances of B and still have identical code. This is a feature that I think should NOT have been implemented in C#, so I am glad to see that it isn't. Thanks Luc,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
After googling for a while, I determined that the code I was refering to in C++ would have looked something like this (I think)...
int i = 0;
int j = &i;
j = 5; I think that the previous code forces i and j to always be equivalent, but again, it has been a while since I programmed in C++, so I can't be certain. Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Skippums wrote: int j = &i;
that would not compile, it should be int* j = &i; so there is only a single
int, and a pointer that now points to the same int. So changing it either with i=...
or with *j=... results in changing the single int, whatever way you access it,
it is still a single variable.
|
|
|
|
|
I was wondering if there is a simple number format code for if you only want to see the decimal portion of the number if there are any significant digits to the right of the decimal - otherwise show the number as an integer.
ex. 3.5 -> 3.5 and 3.0 -> 3 (instead of 3.0)
Thanks
Brent
|
|
|
|
|
Use something like:
num.ToString("0.#")
This will display the string representation of the number including the first significant digit to the right of the decimal point if required.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
I have an app that connects to a db in the Data Directory for Website Project. I am able to connect to the database fine locally. However, after I uploaded my project to my hosting provider's server and try to process a form that does a sql insert, I receive the following error:
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure my be caused by the fact that under the default settings SQL server does not allow remote connections. (provider: Sql Network Interfaces, error 26 - Error Locating Server/Instance Specified.
My connection string to the datasource is as such in my webconfig file:
connectionString="DataSource=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|DefinaBackEnd.mdf;IntegratedSecurity=True;ConnectTimeout=30;User Instance=True"
and the call to the connecting string is called as such:
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DefinaBackEndConnectionString"].ConnectionString);
conn.Open();
Can someone please assist with how to resolve this as this site just looks for a sql db file as opposed to an instance of sql server itself. Thanks to all in advance.
|
|
|
|
|
Hi, let's take this piece of code:
Engine newEngine = new Engine(200, "PS");
Engine oldEngine = null;
oldEngine = Car.Engine;
Car.Engine = newEngine;
...
Car.Engine = oldEngine;
If Engine is a class (reference type) , shouldn't oldEngine share the same value like newEngine ? Right now they have different values.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
No... Basically, the variables are pointers to objects (ie, addresses). Therefore, your code does the following:
Engine newEngine = new Engine(200, "PS");
Engine oldEngine = null;
oldEngine = Car.Engine;
Car.Engine = newEngine;
...
Car.Engine = oldEngine;
Therefore, newEngine IS NOT equal to oldEngine or Car.Engine, but the other two are equal. Hope this helps,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Let's say I have an assembly whatever.dll. I have an app where I want to load that assembly dynamically at runtime (it implements an interface that I know about already) and all I have to go on is the filename. If I do this:
<br />
Assembly assembly = Assembly.LoadFrom(@"C:\somecrazypath\bin\Debug\whatever.dll");<br />
foreach (Type type in assembly.GetTypes())<br />
{<br />
if (type.GetInterface("IMyInterface") == null)<br />
{<br />
continue;<br />
}<br />
<br />
object ibaseObject = Activator.CreateInstance(type);<br />
LoadedModules.Add((IMyInterface)ibaseObject);<br />
}<br />
Then it works great. I can handle events from the object in whatever.dll, and I have a reference to it that works as expected. However, that doesn't allow whatever.dll to have it's own config file, which is also a requirement. So in doing some research, it seems that if you load an object in it's own appdomain, then it can have it's own app.config (read here). So that seemed perfect, but the problem is that I just can't get the code to load right. If I do this:
<br />
AppDomainSetup ads = new AppDomainSetup();<br />
ads.PrivateBinPath += @"C:\somecrazypath\bin\Debug\";<br />
ads.ApplicationBase = @"C:\somecrazypath\bin\Debug\";<br />
ads.ConfigurationFile = @"C:\somecrazypath\bin\Debug\whatever.dll.config";<br />
AppDomain ad = AppDomain.CreateDomain("Whatever", null, ads);<br />
byte[] _assembly = loadFile(@"C:\somecrazypath\bin\Debug\whatever.dll");<br />
ad.Load(_assembly);
I get a filenotfound exception stating that it could not find whatever.dll or one of its dependencies. For the purposes of testing, I made sure that whatever.dll does not have any dependencies (no references other than System, System.Configuration, System.Data, and System.Xml) and I had it inherit MarshalByRefObject instead of my base class to eliminate that as a possible problem. I'm really at a loss as to why it can't seem to find the file. From reading online, it seems that the problem is because it is in a different path than the currently running appdomain, but I would have expected that setting the privatebinpath and the applicationbase on the new appdomain should have fixed that. I did find another report of the same problem here but the answer is incorrect. Passing the full path\filename to createinstanceandunwrap doesn't really fix it.
Has anyone run into this problem before?
|
|
|
|
|
I did just check, and I can load the assembly to the new appdomain just fine if I also place a copy of it in the running application's applicationbase directory. This works even if I don't change the absolute path I use to load whatever.dll. So it seems that if the dll is available to the current appdomain, then I can instance it in a new appdomain as well, but not if it is in a different directory.
|
|
|
|
|
Hello there,
I have made a small console application in C# which I have built and deployed to my local machine, I call it using a batch file to retrieve back any error codes it happens to throw back. It works no worries on my local machine, but I have placed it on a network share I get a load of permissions errors. I have searched round now for days looking for an answer and mainly, I think got it down to a permissions problem. I have increased the security on the local intranet, my computer and every other zone but still I get errors.
I have tried signing the application using visual studio properties of the application but still no joy. I have tried making its own Runtime Security Policy but still no joy. I’m using .net 2 with likes the signed file but when I use the .net 1.1 configuration wizard to trust an application it says it has no strong name despite giving the application one in Visual Studio. I have even tried installing the certificate that visual studio generates on the remote machine but to no joy.
The error I get when I run the program on the remote machine I get this error if I take away all the signing and ClickOnce manifests signing and disable ClickOnce Security Settings is :
Unhandled Exception: System.Security.SecurityException: System.Security.Permissions.SecurityPermission at PDF_to_TIFF.Program.Main(String[] args) The type of the first permission that failed was: System.Security.Permissions.SecurityPermission The demand was for: <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode"/>
And the error I get if I have all the signing switched on is:
Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'PDF to TIFF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d010d2ef76c6f036' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417) File name: 'PDF to TIFF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d010d2ef76c6f036' ---> System.Security.Policy.PolicyException: Required permissions cannot be acquired. at System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Boolean checkExecutionPermission) at System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Int32& securitySpecialFlags, Boolean checkExecutionPermission)
Please Help, this has almost driven me to point of insanity
|
|
|
|
|
We have a .NET console app that runs on our Win2003 server and processes a lot of network traffic.
After several days of running, we've discovered the app eating up all the memory on the machine -- nearly 2GB of memory. It brings the machine to a crawl, we start getting OutOfMemoryExceptions, all fun stuff.
Here's the kicker: I wrote some code so that I could type "garbage collect" in the console, and it would programmatically force a garbage collection (it calls GC.Collect() ). I went to the console app this morning, see it throwing OutOfMemoryExceptions and eating 2GB of memory - I type "garbage collect" in the console, and the memory goes down to a reasonable size and the app magically starts working again, no OutOfMemoryExceptions.
Has anyone ever seen anything like this? Any ideas why the garbage collector isn't working?
|
|
|
|
|
Hi Judah,
I have no experience with Win2003 Server nor do I run programs that long. Anyway:
AFAIK there are only two ways to either run out or leak memory:
1. keeping references to managed objects that are no longer required;
2. not releasing unmanaged resources (i.e. forgetting to implement and/or call Dispose).
If your program runs out of memory, it must be violating 1 and/or 2. If it then recovers after
executing a particular piece of code, then it seems to me that piece of code is remedying 1, 2
or both. So I would suggest you inspect that piece to discover what is happening.
FWIW: If you want to implement some caching, make sure to use WeakReference objects.
BTW: 2GB in a couple of days isn't much, it is around 1MB/minute.
As an alternative idea, the gc probably uses some lower priority threads, so if your server is
heavily loaded, it just might fail to retrieve old generation objects in time. I suggest you
check its CPU load overall and in particular when the problems show.
Hope this helps.
|
|
|
|
|
Luc,
Thanks for the reply.
#1 doesn't seem right, since it wouldn't explain the garbage collection. If I was violating #1, for example, memory would still be high after I force a GC.
#2 doesn't seem right either, since forcing a garbage collection wouldn't magically free unmanaged resources, right? In other words, memory would still be high if I was forgetting to release unmanaged resources, since the unmanaged resources would never get freed, even if I force a GC.
What do you think?
|
|
|
|
|
Hi Judah,
if all it does is GC.Collect() then you are right of course, but since you did not show any
code my best guess was to assume something else also happens when you type "garbage collect"
on your console.
As for unmanaged resources, it is still not clear to me; my advice is to call Dispose() or Close()
[if it exists] as soon as on object is no longer needed; others claim a class with Dispose() also
has a finalizer that will take care of things, but I am not convinced of this.
As always: when the whole thing does not behave the way you expect it to, everything must be
suspected, al prior assumptions must be scrutinized.
|
|
|
|
|
Luc Pattyn wrote: if all it does is GC.Collect() then you are right of course
Yep, that's all it does.
Luc Pattyn wrote: As for unmanaged resources, it is still not clear to me; my advice is to call Dispose() or Close()
Yes, right. To the best of our knowledge, we're calling dispose everywhere possible. I guess I'm gonna have to do some profiling of the app over several weeks. Blech. Thanks anyways, Luc.
|
|
|
|
|
You might want to consider using PerfMon as well, and monitor the garbage collections.
|
|
|
|
|
You're welcome.
Good luck with the profiling, and don't hesitate to report your progress.
|
|
|
|
|