|
I have made small testing app. Iniatialy I have used database connection via IDE (Data Sources -> Add New Data Source), later I have shifted my project to another PC so I had to change Data source.
I have removed old data source from IDE, attached database to another server and stored connectiong string in App.config file.
BUT when I tried to reach this information first time I found out there were more than one conn string!
Old one (which was never in App.config!) and new one.
My confusion was even greater because I haven't had .config file (nor -.settings) prior the change of data source.
Where is old connection string stored? It's not in App.config!
I made ad hoc solution for the moment, method shown passes first usable connection string:
<br />
public static bool ProvjeriKonekciju()<br />
{<br />
bool povrat = false;<br />
SqlConnection conn = null;<br />
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);<br />
ConnectionStringsSection section = config.ConnectionStrings;<br />
ConnectionStringSettings settings;<br />
<br />
for (int i = 0; i < section.ConnectionStrings.Count; i++)<br />
{<br />
settings = section.ConnectionStrings[i];<br />
if (settings == null) continue;<br />
<br />
conn = new SqlConnection(settings.ConnectionString);<br />
try<br />
{<br />
conn.Open();<br />
if (conn.State == ConnectionState.Open)<br />
{<br />
povrat = true;<br />
_ConnString = settings.ConnectionString;<br />
povrat = true;<br />
break;<br />
}<br />
}<br />
catch (SqlException sqlex)<br />
{<br />
Debug.WriteLine(sqlex.ToString());<br />
}<br />
catch (Exception ex)<br />
{<br />
Debug.WriteLine(ex.ToString());<br />
}finally<br />
{<br />
conn.Dispose();<br />
}<br />
}<br />
return povrat;<br />
}
How can I eliminate the intruder?
I'm using Visaul C# 2005 Express.
Help.
I'm not native English speaker, so excuse me.
Feel free to point out bad code aswell.
|
|
|
|
|
Help please!
|
|
|
|
|
Connection strings can also be stored at the machine.config level. So if you are seeing another connection string it can be from there.
A better way to access the connection string if you are using .net 2.0 would be to get it from the ConfigurationManager.ConnectionStrings. This should be only the value you have set in the app.config file. When you open the configuration file like you have in the above code it may be looking into the machine config as well.
Hope that helps.
Ben
|
|
|
|
|
No. That was my first choice, but it also has sent me two connStrings.
I thought code shown above will help me (well that was the idea I got after reading msdn).
|
|
|
|
|
Sir,
I got these two exceptions, 1. System.Runtime.InteropServices.GUIDAttribute - cant be specified multiple times and
2. System.CLSCompliantAttribute - cant be specified multiple times with Indentical parameters also.
Why do I get these exceptions and how can I clear these exceptions. Thank you.
Regards,
S/W Engineer
Akebono Soft Technologies
aleem_abdul@akebonosoft.com.
|
|
|
|
|
I'm guessing you have a GUIDAttribute and a CLSCompliantAttribute specified more than once for a class? The clue is in the error message.
|
|
|
|
|
But I am not getting how should I clear it. Pls. give me some example how to clear that error. Thank you.
Regards,
S/W Engineer
Akebono Soft Technologies
aleem_abdul@akebonosoft.com.
|
|
|
|
|
Obviously, if the error says 'don't specify this multiple times', you need to only specify it once, whereas you're currently specifying it MORE than once.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus - Pointing out the blindingly obvious to those that refuse to see it since 2000!
|
|
|
|
|
Both of these attributes are generally specified in the AssemblyInfo file. This file is included only once in the project, so the attributes are defined only once. The attributes do not exist in this file by default, so you would need to add them.
If you think these are defined more than once (which the compiler obviously does), then search using "Find in Files" for the attribute names and remove the duplicates.
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
Are you not perhaps specifying class targeted attributes on methods?
|
|
|
|
|
Hi,
Is it possible to set the load order for the windows service? So for example, I want to have my windows service loaded last after a system boot up. Is that possible? Thanks for and any replies.
~Jacky
|
|
|
|
|
I don't know of any way that you can force a service to load last, but you can set a dependency on other things. I had an issue where the Message Queue MSMQ needed to load first before my service.
In the ServiceInstaller file you add this:
this._serviceInstaller.ServicesDependedOn = new String[1] {"Message Queuing"};
So if there are other services that need to be running first. Just put there name in the above code instead of the "Message Queuing".
Hope that helps.
Ben
|
|
|
|
|
There used to be some Netscape Browser lines in machine.config. I am not able to locate them in .NET Framework 2.0 machine.config.
Any clues?
|
|
|
|
|
Hi,
I have this problem on closing sockets. When my server initiates it listens request through a tcp port like so...
tcpChannel = new System.Runtime.Remoting.Channels.Tcp.TcpChannel(8005);
Now, when my server shuts down and then restarted. It gives me this error,
"only one usage of each socket address (protocol/IP address/port) is permitted."
It seems the port is not closed or there is a timing issue.
The Solution:
So to fix this, I want to scan the socket 8005 and see if its closed or not before my server starts. If it is open, then close it. My server runs on a window service so it can do this. It seems I only have this problem for dual core processors. Other processor worked fine.
So does anybody know how to implement this solution in C# code?
Thanks in advance for any help!
~Jacky
|
|
|
|
|
Hi,
i am working in a Web application, which is using the Setup to install in a system, now i have to customize the MSI Application, for new different cases by using a radio button,i am new to MSI programming possible if so any please send me any resource
Thx for u r help in advance,
|
|
|
|
|
|
I am working on a composite DateTime picker control.
I would like to expose a ValueChanged event when the composite value changes.
Internally, I handle the DateChanged and TimeChanged events.
Private Sub DatePicker_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DatePicker.ValueChanged<br />
If Not bInternal Then<br />
CombineValues()<br />
End If<br />
End Sub<br />
<br />
Private Sub TimePicker_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TimePicker.ValueChanged<br />
If Not bInternal Then<br />
CombineValues()<br />
End If<br />
End Sub<br />
<br />
Private Sub CombineValues()<br />
Dim dt As Date = DatePicker.Value<br />
Dim tm As Date = TimePicker.Value<br />
<br />
Dim s As String<br />
s = String.Format("{0} {1}", dt.ToString("d"), tm.ToString("t"))<br />
_date = Date.Parse(s)<br />
End Sub
He was a snowflake, like other "unique" snowflakes, falling down, getting stepped on, and pushed aside to disappear.
|
|
|
|
|
You can create a custom event for your composite control. The subject of creating custom events is a little confusing and lengthy. Check out this article on creating events:
http://www.codeproject.com/vb/net/StepByStepEventsInVBNET.asp[^]
Once you've declared your event to be public you can expose it outside you control just like any other control.
Cheers!
Richard
May your code be error free
|
|
|
|
|
Thanks. I'll check that out.
He was a snowflake, like other "unique" snowflakes, falling down, getting stepped on, and pushed aside to disappear.
|
|
|
|
|
Worked like a charm.
Now to write an article.
He was a snowflake, like other "unique" snowflakes, falling down, getting stepped on, and pushed aside to disappear.
|
|
|
|
|
Hello all,
I'm new to remoting and have been given a task which I'm having trouble with.
We have a bunch of windows services that perform various tasks, running on a remote computer. We need a way to interrogate the services remotely and return a number of given values from variables/props INSIDE the service. This will then be used to create a dashboard of values from our services at any given time so we can see they are all working properly.
I have setup a test program that uses a simple windows service as the component host, which registers my remote object to be instantiated by my test client program.
My question is, how do I refer back from the remoting object to my service to obtain the values required? As far as I can see, the remote object itself has no knowledge of the component host that it was instantiated from. I've read lots of text on remoting but nothing seems to mention access to the component host of the remoting object.
I've tried using ManagementObject and iterating through the services running, and I can find my service, but I can't find a way from there to access the custom properties of my service class, only the base properties of all services. Is there another way to obtain this information using the ManagementObject? Or is there a way from my remote object to reference back to its component host?
I tried using GetActiveObject() as well but that seems to not work for services
Any help would be much appreciated, there's probably a easy way to do this that I can't see.
Thanks
|
|
|
|
|
Im trying to read a xml-file with a StreamReader. For the moment I'm using the following code.
<br />
streamReader = new StreamReader(stream, System.Text.Encoding.Default);<br />
string feedData = streamReader.ReadToEnd(); <br />
I'm using System.Text.Encoding.Default so that I can get some swedish characters working. But I'm having problem when reading a xml-file that's encoded with UTF-8. In the beginning of the xml-files you have the encoding for the file, so I have tried this code:
<br />
streamReader = new StreamReader(stream, System.Text.Encoding.Default);<br />
string feedData = streamReader.ReadLine();<br />
if(feedData.indexOf("UTF-8") != -1)<br />
streamReader = new StreamReader(stream, System.Text.Encoding.UTF-8);<br />
<br />
string feedData += streamReader.ReadToEnd(); <br />
My plan was to read the first line, check if it's encoded with UTF-8 and then change the stream. This doesnt work at all... Is there anyway you can change the encoding for a stream once it's initialized or can you encode the string afterwards?
|
|
|
|
|
Deal ALl,
How would I be able to generate MS Project file .Any Hint/idea would be appreciated.
Regards,
Lq
|
|
|
|
|
Dear gurus,
currently I learn how to write my programs based on plugin-technology in c# and I have a lot of open questions.
Can anybody suggest a good book on this subjet?
Thanks in advance
|
|
|
|