|
my connectionstring is corrent because when I change my server Name to (local) my app haven't any error...
...
|
|
|
|
|
Basically three possibilities:
1. Your SQL Server isn't configured to use TCP/IP, use Configuration Manager at server
2. Your connection string is faulty, bad ip-address, port etc
3. IP traffic isn't routed to server, for example because of an firewall
The need to optimize rises from a bad design
|
|
|
|
|
- In sqlserver I see tcp/ip connection & I ticked it...
- If my connectionstring faulty ,i can not connect with it localy...
my connectionstring:
public void Connect()
{
string cs = "Server = 192.168.10.190; database = DB1; user=u1; password=123";
con.ConnectionString = cs;
con.Open();
}
|
|
|
|
|
Few questions:
- is the SQL Server running on the same computer where you're running the app?
- if you can connect to it locally but not remotely, what's the difference in connection string?
The need to optimize rises from a bad design
|
|
|
|
|
diference of it , is i change servername to (local)...
I have some pc with Lan network in one of these I have sqlserver with my database, and in other pcs i have app for connect to that.
|
|
|
|
|
Then the three choices I listed are most common reasons. It's a very different situation to use IP than to connect to localhost.
Few things you should check,
- try to ping the IP-address
- check on server side that the listening port is 1433 or if it isn't, specify the correct port in connection string
- check on server side that the other pc can listen to port 1433 (no Windows firewall blocking)
- check that it isn't a named instance on the server or if it is, specify the instance name in connection string
The need to optimize rises from a bad design
|
|
|
|
|
hi all.
i need to make a call to a method asynchronously. this method accepts arguments. the method also returns a value that is then used to modify a form obviously created by the main thread.
to keep things simple, i created a prototype of what i'm trying to do. here's the code:
public partial class Form1 : Form
{
public delegate int SomeMethod();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SomeMethod method = IntFetcher.SlowFetch;
method.BeginInvoke(EndFetchInt, method);
}
public void EndFetchInt(IAsyncResult result)
{
SomeMethod method = result.AsyncState as SomeMethod;
int i = method.EndInvoke(result);
MethodInvoker mi = new MethodInvoker(this.AddToList);
this.BeginInvoke(mi, i);
}
public void AddToList()
{
int i = 0;
ListViewItem lvi = new ListViewItem();
lvi.Text = i.ToString();
lvi.SubItems.Add(DateTime.Now.ToString());
listView1.Items.Add(lvi);
}
public void AddToList(int data)
{
ListViewItem lvi = new ListViewItem();
lvi.Text = data.ToString();
lvi.SubItems.Add(DateTime.Now.ToString());
listView1.Items.Add(lvi);
}
}
public static class IntFetcher
{
public static int SlowFetch()
{
Thread.Sleep(3150);
Random random = new Random(DateTime.Now.Millisecond);
return random.Next(100, 500);
}
}
I had to create the AddToList() method to be confirm if the code was being called at all and to determine if it could modify the listview control. It did. But i still couldnt figure out a way to pass the value returned from the function to it.
I used MethodInvoker cos without it, I got an exception telling me that the running thread could not modify the control as it was created by the main thread.
Any contributions will be appreciated. Thanks.
|
|
|
|
|
|
i still got this exception
Cross-thread operation not valid: Control 'listView1' accessed from a thread other than the thread it was created on.
while calling the AddToList() method directly from the callback method using the procedure outlined on that url.
combed thru msdn and got this url http://msdn.microsoft.com/en-us/library/ms171728.aspx which is supposed to help make thread-safe calls to windows form controls.
trying to understand the methods outlined there.
|
|
|
|
|
First, based on documentation for MethodInvoker : This API supports the .NET Framework infrastructure and is not intended to be used directly from your code
Second, presumably the MethodInvoker executes the method passed in another thread so it basically the problem is exactly what the error says.
Take a look at BackgroundWorker Class[^]. I believe it would be helpful in your case.
The need to optimize rises from a bad design
|
|
|
|
|
Thanks Mika, but i got it working already. the problem i had was marshalling the background thread to the main one. this was the modification i made to get it to work.
public void EndFetchInt(IAsyncResult result)
{
SomeMethod method = (SomeMethod)result.AsyncState;
int i = method.EndInvoke(result);
AddToList(i);
}
delegate void _addToList(int data);
public void AddToList(int data)
{
if (this.listView1.InvokeRequired)
{
this.Invoke(new _addToList(AddToList), data);
}
else
{
ListViewItem lvi = new ListViewItem();
lvi.Text = data.ToString();
lvi.SubItems.Add(DateTime.Now.ToString());
listView1.Items.Add(lvi);
}
}
i would have had to do the same if even if i had used the BackgroundWorker class.
|
|
|
|
|
Glad you got it solved!
Yeah, you have had to do the same in every implementation, but there was these two reasons why I suggested BackgroundWorker:
- if I understood correctly, MethodInvoker shouldn't be used. If it's internal, it's not well documented and there are no quarantees for backward compatibility in future versions
- with BW the model is easier to implement and therefore also more understandable
But then again, are those valid reasons at all fully depend on your needs.
Happy coding
The need to optimize rises from a bad design
|
|
|
|
|
|
Your code works. I replaced the createMailBody with the string directly.
string strImage = "TestImage.gif";
string strTitle = "HTML File";
string strMailBody = @"<html><body> <table> <tr> <td><img src="$image$"/></td> <td> $title$</td> </tr> </table></body></html>";
strMailBody = strMailBody.Replace("$image$", strImage);
strMailBody = strMailBody.Replace("$title$", strTitle);
I assume the problem is that you don't get the right string from the createMailBody method.
Eslam Afifi
|
|
|
|
|
Sorry for delay...
iam using this to send a mail. Problem is, at the receiver end image doesn't display. How to solve this?
|
|
|
|
|
The img src must be an absolute url or you can use attached images as described here[^].
Eslam Afifi
|
|
|
|
|
I got a big Access database I'd like to convert to MS SQL Server 2005
and I'm looking for an efficient automated tool to convert data (over
1 400 tables), query, forms and interface.And i want to convert the access forms to C#
Does somebody can provide me with a list or, at least,a suggestion of
tools that has already been used or well known for their
efficiency.(except upsizing wizard and DTS, I tried with no success,
since I'm not a programmer)
Thanks,
Guy
|
|
|
|
|
you can move the tables over to sqlserver using SSIS. i dont know about the forms and interfaces tho. you might have to create those yourself
|
|
|
|
|
There's nothing that will convert the forms, or anything user interface, to C# or any other language. You'll have to recreate all of this yourself.
|
|
|
|
|
You can try:
http://www.microtools.us
but I haven't tried this myself.
David Anton
http://www.tangiblesoftwaresolutions.com
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
VB & C# to Java Converter
Java to VB & C# Converter
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: convert VB, C#, or Java to C++/CLI
|
|
|
|
|
Here is the code snippet, with Reflection code. I have taken the code for Reflection from below link
"http://www.codeproject.com/KB/cs/C__Reflection_Tutorial.aspx"
public bool SaveLoginInfo(string UserName, string Password)
{
if (objForDBTransactions == null)
{
objForDBTransactions = new RegMgr();
}
try
{
bool bSaveDone = false;
object[] ArrayParam = new object[] { UserName, Password, objForDBTransactions };
//=================================================================================================== <b>//Way 1: It is throwing an error - Object reference not set to the instance of the object</b> //Type Objtype = Type.GetType("Login");
//MethodInfo myMethodInfo = Objtype.GetMethod("Save<string>");
//myMethodInfo.Invoke(Objtype, ArrayParam);
//===================================================================================
<b>//Way 2: It is throwing an error - AddressBook.Login.Save does not exist</b>
Type ObjType = typeof(Login);
Object obj = Activator.CreateInstance(ObjType);
bSaveDone = (bool)ObjType.InvokeMember("Save <T>", BindingFlags.InvokeMethod, null, obj, ArrayParam);
// Tried with Save, Save<string>, Save<T> however none is working.
//=================================================================================================== return bSaveDone;
}
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show(e.Message);
System.Windows.Forms.MessageBox.Show(e.Source);
return false;
}
}
Here is Save function of Login class
public bool Save <T>(T UserName, T Password, RegMgr objRegmgr)
{
this.UserName = UserName.ToString();
this.Password = Password.ToString();
objRegmgr.SaveLoginInfo(this);
return true;
}
Thanks in Advance
|
|
|
|
|
puneet.bhatnagar123@gmail.com wrote: http://www.codeproject.com/KB/cs/C__Reflection_Tutorial.aspx
That article has a discussion board. Consider posting your question there with a neat subject.
|
|
|
|
|
puneet.bhatnagar123@gmail.com wrote: Type Objtype = Type.GetType("Login");
Please go read the documentation on MSDN, and what they say you need to pass into that function. You havent, and hence the error.
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 alpha 4a out now (29 May 2008) ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
Way 3:
bSaveDone = new Login().Save(UserName, Password, objForDBTransactions);
Have you actually sat down and thought about why you are using generics and reflection to achieve some very simple tasks?
|
|
|
|
|
Hi,
Thanks for the way3. I have already tried with that and that was working fine for me. The reason why I am using Reflection and Generics is because we gonna use these two concepts in our next project which still is in design phase. So just to learn I am using them.
Thanks for your efforts.
Thanks & Regards,
Puneet
|
|
|
|