|
The following is what I am trying to prevent:
The server is currently accessing a file and a user goes to get that same file. Currently if I do nothing what will happen is the user will access that file without knowing that they are in read only and when they go to save it will crash.
So I want a message to pop up when you open the file to let you know you are read only, and when they go to save they get another message saying they can't save the file but takes them to a Save As window.
|
|
|
|
|
That sounds simple enough:
1. on user open, first try open in Mode.readwrite, if that fails, try open in Mode.read
and alert user
2. on user save, try save the file, if that fails, try to "save as".
I dont see the problem. If coded correctly, a save never "crashes".
Things to keep in mind:
1. you need a try-catch for each operation that might fail (each try in above text)
2. dont carry any file state information from 1. (try to open) to 2. (try to save) since
there is no need to, and the state may have changed anyhow.
3. Dont forget to always Dispose() or Close() things that need it (such as FileStreams).
|
|
|
|
|
|
I am doing .Net Remoting and i get following exception what can be the reason?
1. Interface
<br />
public interface DeptInterface<br />
{<br />
bool ExecuteSelectCommand(string selcommand);<br />
string GetRow();<br />
void Init();<br />
}<br />
<br />
2. Server.cs
<code><br />
public partial class Form1 : Form<br />
{<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
}<br />
public class CustServer : MarshalByRefObject, DeptInterface<br />
{<br />
private SqlConnection myConnection = null;<br />
private SqlDataReader myReader;<br />
<br />
public CustServer() { }<br />
<br />
public void Init()<br />
{<br />
try<br />
{<br />
String strConn = "Data Source=KPTEST1;Initial Catalog=Store;Integrated Security=SSPI";<br />
myConnection = new SqlConnection(strConn);<br />
myConnection.Open();<br />
if (myConnection == null)<br />
{<br />
MessageBox.Show("OPEN NULL VALUE =====================");<br />
return;<br />
}<br />
}<br />
catch (Exception es)<br />
{<br />
MessageBox.Show("[Error WITH DB CONNECT...] " + es.Message);<br />
}<br />
}<br />
public bool ExecuteSelectCommand(String selCommand)<br />
{<br />
try<br />
{<br />
MessageBox.Show("EXECUTING .. " + selCommand);<br />
SqlCommand myCommand = new SqlCommand(selCommand);<br />
if (myConnection == null)<br />
{<br />
MessageBox.Show("NULL VALUE =====================");<br />
return false;<br />
}<br />
myCommand.Connection = myConnection;<br />
myCommand.ExecuteNonQuery();<br />
myReader = myCommand.ExecuteReader();<br />
return true;<br />
}<br />
public string GetRow()<br />
{<br />
if (!myReader.Read())<br />
{<br />
myReader.Close();<br />
return "";<br />
}<br />
int nCol = myReader.FieldCount;<br />
string outstr = "";<br />
object[] values = new Object[nCol];<br />
myReader.GetValues(values);<br />
for (int i = 0; i < values.Length; i++)<br />
{<br />
string coldata = values[i].ToString();<br />
coldata = coldata.TrimEnd();<br />
outstr += coldata + ",";<br />
}<br />
return outstr;<br />
}<br />
Client.cs
<br />
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
MessageBox.Show("TEST1");<br />
bool ensureSecurity = true;<br />
ChannelServices.RegisterChannel(new TcpClientChannel(), ensureSecurity);<br />
dept = (DeptInterface)Activator.GetObject(typeof(DeptInterface), "tcp://KPTEST1:8080/CustServer");<br />
if (dept == null)<br />
{<br />
MessageBox.Show("TCP SERVER OFFLINE ...PLEASE TRY LATER");<br />
return;<br />
}<br />
dept.Init();
MessageBox.Show("TEST2");<br />
}<br />
It gives exception at dept.Init() ? What can be the reason please help me...
|
|
|
|
|
I'm guessing that just by the error message the other machine you're connecting to doesn't want to be connected. A firewall perhaps?
|
|
|
|
|
Ed, I am doing on the same machine localhost.
By the way when i removed ChannelRegistry from Client.cs I am getting now following exception:
System.Runtime.RemotingException: Requested Service not found
at dept.Init() method.
HELP ((
|
|
|
|
|
Sorry you've exhausted my remoting experience
|
|
|
|
|
this is not fair to me anyway if u dont want to help. Its ok
|
|
|
|
|
Remember that we are giving up free time to help
|
|
|
|
|
shah123 wrote: What can be the reason
I don't see anywhere in your server code where you setup the Tcp Channel that you are trying to use in the client.
|
|
|
|
|
Sorry it was in Server Form_Load method.
<br />
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
<br />
TcpServerChannel tsc = new TcpServerChannel(8080);<br />
ChannelServices.RegisterChannel(tsc);<br />
RemotingConfiguration.RegisterWellKnownServiceType(typeof(CustServer), "CUSTOMER_SERVER2", WellKnownObjectMode.Singleton);<br />
textBox1.Text = "SERVER RUNNING ..";<br />
textBox1.ReadOnly=true;<br />
<br />
}
|
|
|
|
|
shah123 wrote: DeptInterface
I don't think you can register a "CustServer" and then in the client Activate a "DeptInterface".
Also with Remoting, I recommend using namespaces.
|
|
|
|
|
so please tell me the way... I will be very thankful to you.
|
|
|
|
|
It has been awhile since I've done remoting....but you cannot run a server as a windows form. That is just not right. For a good primer, Ingo Ramer has a great book on remoting that will help you through your problems of creating a great server. Also if you google for remoting you can also find some examples.
My services always ran under IIS so that allowed the IIS host to handle all of the connection issues and my classes existed as a service within the web server.
However, the long term direction of Microsoft is to eliminate .NET Remoting so if it is at all possible you should move to using WCF instead for you deployment.
|
|
|
|
|
Hey Thanks for ur replies....i really appreciate...but I think developing a parser or lexical analyser will be a complex task, My project just needs to provide a SQL syntax checking as a feature...so can we have a simpler approach?
|
|
|
|
|
hello iam a fresher
my problem is if i click previous button first time it is going to next question after clicks the previous button it is going to previous question . for example at 8th question i clicks on previous button it is going to 9th question then second time i clicks on previous button it is going to 8 th question then 7th then 6th then 5th...........
<pre>
{
if(dg1.CurrentPageIndex < 1 )
return;
else
if (dg1.CurrentPageIndex > 0)
{
dg1.CurrentPageIndex -= 1;
SwitchLebel(dg1.CurrentPageIndex);
}
is it correct or not
srinivas
|
|
|
|
|
srinivassam wrote: is it correct or not
Probably not, since you dont like the results.
Show more actual code to help us help you...
|
|
|
|
|
I have the following list:
System.Collections.Generic.List<Employee> employees= new System.Collections.Generic.List<Employee>();
Employee class has the following fields(for simplicity):
EmployeeId
EmployeeName
Department
JobTitle
etc.
I want that the new employee instance can be added employees list only if the list does not already contain it. I think the Exists() method may be used for this checking. But i dont know how use it.
Kindly, give me articles' and examples' links to understand the usage.
Thanks!.
|
|
|
|
|
MSDN has nice examples about that. Exists allows you to determine if list contains an element that matches a specified search pattern. Contains method tell if an element is in list
|
|
|
|
|
Thanks!.
But i wana understand the use of Predicate with custom objects rather than premitive type in Exits() method.
Thanks once again!.
|
|
|
|
|
lossy wrote: I want that the new employee instance can be added employees list only if the list does not already contain it. I think the Exists() method may be used for this checking. But i dont know how use it.
Kindly, give me articles' and examples' links to understand the usage.
Have you considered reading the documentation? What does it say about its use?
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
* Reading: Developer Day 5
Ready to Give up - Your help will be much appreciated.
My website
|
|
|
|
|
Determines whether the List contains elements that match the conditions defined by the specified predicate.
(from MSDN)
|
|
|
|
|
|
Hi
The following code declare the predicate match method in the employee class.
in order to check if employee instance exists within the list, just construct new employee class with the relevant parameters (i used id as key) and call the Exists method
class Program
{
class Employee
{
private long m_id;
public Employee(long id)
{
m_id = id;
}
public bool IsMatch(Employee employee)
{
return (m_id == employee.m_id);
}
};
static void Main(string[] args)
{
List<employee> employees = new List<employee>();
employees.Add(new Employee(1));
employees.Add(new Employee(2));
employees.Add(new Employee(3));
employees.Add(new Employee(4));
employees.Add(new Employee(5));
Console.WriteLine(employees.Exists(new Employee(3).IsMatch) != null);
}
}
|
|
|
|
|
Thanks!. for alternative solution.
|
|
|
|