|
this is only required if you have installed Express Edition.
Open "SQL Server Management Studio Express
Connect to your Database
Right Click on the Database in Object Explorer
go to Properties
select "Security"
Now in Server Authentication Mode
select "SQL Server And Windows Authentication Mode"
Restart the SQL Server Service (if you dont know how then restart the computer)
if still have the problem then
go to
Start
SQL Server 2005
Configuration Tools
SQL Server Surface Area Configuration
Then select "SQL Server Surface Area Configuration for Service & Connection"
now select "Remote Connection"
tick on "Remote and Local Connection"
again tick on "Use Both TCP/IP and Named Pipe"
Now go to Service "Stop" it and then "Start" it.
also its not advisable to use "sa" user at deplyoment (client side).
create one database user and give it specific rights
there are 2 ways
either you specify the sql script at the deployment project, or you can run set of sql commands from the application, if the application cannot connect to specific database in sql server (for this you have to connect to the sql server using Windows Authentication mode).
|
|
|
|
|
Hello all,
I've been assigned a bug in a multi-threaded windows application method that serves lookup data. The method fills a static list object full of simple data objects. When only one thread hits the method the method executes rapidly. The SQL stored procedure that is returning the results is optimized and runs quickly. You can test it using a T-SQL call and it runs in less than a millisecond. When one thread accesses the method the code returns just as quickly. But when more than one thread hits the method at the same time load up of the static list object becomes slower in an exponential fashion, driving system resource usage up and taking much longer than expected. After the list runs then the usage drops again, since the method is no longer called until the application is recycled.
private static List<DataObject> _list = null;
public static List<DataObject> GetList()
{
if (_list == null)
{
_list = new List<DataObject>();
SqlDataReader reader = null;
SqlConnection connection =
new SqlConnection(ConnectionString);
SqlCommand command = null;
// Set up a new command
command = new SqlCommand("GetList", connection);
command.CommandType = CommandType.StoredProcedure;
reader =
command.ExecuteReader(CommandBehavior.CloseConnection);
while (reader.Read())
{
DataObject instance = new DataObject();
instance.ID = reader["ID"] != DBNull.Value &&
reader["ID"] != null ? (int)reader["ID"] : 0;
instance.Name = reader["Name"] != DBNull.Value &&
reader["Name"] != null ? (string)reader["Name"] :
string.Empty;
_list.Add(instance);
}
}
}
Please help me out here, I'm not sure what is causing this behaviour??? Is there something in the code that needs to be fixed???
I'd really appreciate it!
Thanks
Tina
|
|
|
|
|
Tina P wrote: But when more than one thread hits the method at the same time
Are multiple threads trying to populate the list at the same time? Try locking
MSDN Locking
hope this helps
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hello Bob,
I think that is precisely what's happening...i looked into locking a little bit, but I can't quite figure out where to put the lock statements and where to unlock? Would you be able to point me in the rite direction and perhaps show me some code? I'd really appreciate it!
Tina
|
|
|
|
|
i think that the list being static is the bottle neck...
static means "only a single copy of that member can exist at any given time, regardless of how many copies of a class are instantiated".
what i think is happening is thread A, B and C start the method 1ms after each other for arguments sake. let say the method takes 1000ms to complete.
thread A will get access to that static object but B and C will have to wait for A to finish its work with it before B and C may access it. so you expect 1000ms for the three threads to complete the task but now that they have to wait for each other its taking 3000ms.
im not sure if im right but its what makes sense to me, hope it helps
BTW, please use PRE tags when posting code... no one wants to read non-indented code
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.passion != Programming)
|
|
|
|
|
Interesting observation Harvey...I didn't even think about the list being static, but now that you mentioned, its a valid point. However as Bob suggested, I was trying to play with locks on this. I have never done anything multithreaded so I'm not sure how to accomplish that? Any ideas.
On the flip side, if I make the list not static (instance driven) then the whole method needs to be re-writen....see I;m trying to fix this bug with minumum effort so I won't break anything else?
Any thoughts???
Thanks
|
|
|
|
|
i dont think locks will solve the problem because a "lock" might be causing it.
while thread A is using the static object its "locked" from the other threads that also wants to use it, causing them to have to wait for it to be "unlocked".
once again im not sure if this is in fact how the threads are responding to the static object, its just an assumption.
what id do to make sure my assumptions are correct is write a small test app with a static method and multiple threads trying to access it. Then use multimedia timers(these are alot more accurate than System.Windows.Forms.Timer) to see what is happening when and then draw up your own conclusion based on the results.
Then from there you can decide if rewriting the method is necessary
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.passion != Programming)
|
|
|
|
|
It could be as Harvey says, but I suspect a conflict. Using statics for 'static' data is the usual way to do it. I always put a lock on and have yet to experience the problem described (but that doesn't mean it won't happen next time!).
I would code it more or less as per the msdn link
Object thisLock = new Object();
public static List<dataobject> GetList()
{
lock (thisLock)
{
if (_list == null)
{
_list = new List<dataobject>();
etc etc
}</dataobject></dataobject>
The best bet is to try it - its a minimal code change to add the locking.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hi!
You'll also have to make the thisLock static since instance members cannot be accessed from a static function.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Very true - copy and paste from MSDN article error
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Take a look at this question:
If a class does not implements IEnumerable interface,which of the following is cannot be used?
a. GetEnumerator()
b. ForEach
I had to choose one option and I think both are true. Am I correct?
(It was an online test on a widely used website)
modified on Tuesday, July 8, 2008 1:19 AM
|
|
|
|
|
I can create a method on any class called GetEnumerator(), it doesn't have to have anything to do with IEnumerable. Eg
public class DumbClass {
public string GetEnumerator() { return "Good morning";}
}
Not very useful but now I can say
DumbClass x = new DumbClass();
Console.WriteLine(x.GetEnumerator());
ForEach needs an implementation of IEnumerable.
|
|
|
|
|
PaulLinton wrote: I can create a method on any class called GetEnumerator(), it doesn't have to have anything to do with IEnumerable
I meant the one that comes with the interface.
|
|
|
|
|
Nothing "comes with" an interface.
|
|
|
|
|
It's possible for a class to have a GetEnumerator method without actually implementing IEnumerable.
|
|
|
|
|
|
Hi,
I've made a Web Crawler in C#.Net and it crawls a given url in the textbox for all the url's on the page and stores in database.
Then taking one url at a time it again crawls all the urls for email addresses on the contact page of the website.
Now what i want is that when i open my web browser and open google.com search for anything and the results which come out, i mean it gives all the links n urls so i want my tool to work there.
I want my web crawler to work with the google.com results... right now i'm manually providing one url in the textbox for the whole crawling procedures.
I hope i can get good advice and suggestion to solve my problem.
Thanks
Paritosh Tripathi
B.Tech. (C.S.)
|
|
|
|
|
|
Can a windows service be started automatically by an installer? I plan to distribute the service via CD-Rom so the installation needs to be as simple as possible.
"Make it as simple as possible, but no simpler" Issac Newton
|
|
|
|
|
Don't know if it can directly, but you can set it to start on reboot and ask the user to reboot after the install.
|
|
|
|
|
I placed a msgbox in there for sh*t's and giggles, and it worked fine. Then I moved the SetText snippet to FormLoad, and it worked fine. However, it refuses to work in my event handler, and that's when I need to use it. Is this a bug?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using iTunesLib;
namespace WIKDSPK
{
public partial class Form1 : Form
{
private iTunesAppClass m_iTunes = new iTunesAppClass();
public Form1()
{
InitializeComponent();
try
{
m_iTunes.Resume();
m_iTunes.OnPlayerPlayEvent += new _IiTunesEvents_OnPlayerPlayEventEventHandler(m_iTunes_OnPlayerPlayEvent);
}
catch (COMException)
{
Application.Exit();
}
}
private void m_iTunes_OnPlayerPlayEvent(object iTrack)
{
string iTArtist = ((IITTrack)iTrack).Artist;
string iTName = ((IITTrack)iTrack).Name;
string iTAlbum = ((IITTrack)iTrack).Album;
string m_iClipStr = "Now Playing [ Artist: " + iTArtist + " Name: " + iTName + " Album: " + iTAlbum + " ] www.xxxxxxxx.org";
Clipboard.SetText("Test");
}
}
}
PS> The event handlers are working 100%
|
|
|
|
|
I've got to ask this (it's going to sound stupid), but are you pasting it or using Clipboard.GetText()?
I sat up a couple of events and had the Clipboard.SetText(string) run and it copied to the clipboard just fine.
Have you tried stepping through your code?
|
|
|
|
|
As I said. If I move Clipboard.SetText to FormLoad, it works fine. However, if i nest it within my iTunes event handler, it's almost as if it doesn't even exist. Is this an Express Edition limitation? A bug?
The Clipboard.SetText("TEST"); is just for testing purposes... In addition, I know that the event is being handled because if I place MessageBox call in there, pointing to iClipStr, it totally works.
|
|
|
|
|
Put MessageBox.Show(Clipboard.GetText()); under the Clipboard.SetText("TEST");.
If it says "TEST" in the messagebox, then it worked.
|
|
|
|
|
Well, I did that, and I got the MessageBox but the text field was empty. So it's still not forwarding the data to the clipboard. It's driving me nuts! Clipboard works fine everywhere else except my handler. I don't get it. The handler is being called... The MessageBox does come up!
|
|
|
|