|
I have created a service in C#.
The service loads a COM dll (it uses OLE DB classes) on startup which handles the database
connectivity part (SQL server).
When I startup the service it works fine for a local database but when the database is
remote the Open fails with an error.
The exception that is written into the Event Log is as follows:
"[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied."
"System.Runtime.InteropServices.COMException (0x80004005): [DBNETLIB][ConnectionOpen
(Connect()).]SQL Server does not exist or access denied.
To zero-in on the problem I ported the Database related code into a separate exe and found
that it works fine. SO this problem seems specific to a Service.
I am running the service logged is as a System Administrator and given full access to it at
the Remote server.
Has anybody faced this problem before. Pls help.
Coding is injurious to health!!
|
|
|
|
|
1. If you're connecting only to SQL Server and not any other DB systems, use the System.Data.SqlClient instead of OLE DB. These are classes written specifically for SQL Server with a lot of optimizations and additional features over OLE DB.
2. The problem seems to be security. When you put it in a Windows app, it runs under your user credentials (be default). If you are using SSPI to connect to the SQL Server with a trusted connection, your credentials are authenticated and authorized by SQL Server, so you're app can access it.
Typically, most Windows Services use the LocalSystem account. If your connection string is using SSPI and the LocalSystem (SYSTEM) account is NOT added to SQL Server as a viable user that can access the system, you'll get Access Denied.
You should either use a fixed User ID and Password in the connection string, as well as Trusted Connection. Or, continue to use Integrated Security=SSPI and add the SYSTEM account to SQL Server for that database and grant it the rights necessary to run (I wouldn't recommend making it a dbo, though).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Good advice Heath,
One more thing to add, is that if your service and SQL Server are on different boxes then you can't use or add System to an authorized account on SQL Server. Local System, uses a null user and null password to make autorization attempts against remote resources, unless you have null session shares turned on (NEVER DO THIS) it won't work.
You're best be is to create a domain account for your service, configure your service to run under this account and add this account to your sql server as a login and a user in your database.
If you do not have a domain, then as long as the same account exists on both boxes and has the same password you can still connect.
|
|
|
|
|
Did you actually read his question?
Heath Stewart wrote:
1. If you're connecting only to SQL Server and not any other DB systems, use the System.Data.SqlClient instead of OLE DB. These are classes written specifically for SQL Server with a lot of optimizations and additional features over OLE DB.
His data access is being done from a COM dll, not a .NET component. You are answering the wrong question.
Heath Stewart wrote:
Typically, most Windows Services use the LocalSystem account. If your connection string is using SSPI and the LocalSystem (SYSTEM) account is NOT added to SQL Server as a viable user that can access the system, you'll get Access Denied.
He is very clear about the fact that he is _not_ running the service under LocalSystem.
Heath Stewart wrote:
Typically, most Windows Services use the LocalSystem account. If your connection string is using SSPI and the LocalSystem (SYSTEM) account is NOT added to SQL Server as a viable user that can access the system, you'll get Access Denied.
He's also very clear that the database is on a remote machine, in which case granting LocalSystem access won't help at all because they are two unrelated LocalSystem accounts.
Heath Stewart wrote:
You should either use a fixed User ID and Password in the connection string, as well as Trusted Connection
*sigh* I'm not even going to go there.
Fortunately Terry's answer already homes in on what is likely the real problem.
-Blake
|
|
|
|
|
I have written a socket server that accepts a connection over a single port. It now reads data into a string and then creates a hipaa compliant file out of the data. That data is then sent to the mainframe and a response file is created. I then reverse the process and write the data back over the port to the sender. Right now the process is single threaded. Where I get the data, create file, wait for response file, send data. I can do all this in about 3-4 seconds.
I have a few questions that I hope someone can answer...
I need to address multiple request that are sent. How do I thread this process so that multiple transactions (data files) can be dealt with. I am concerned about the sender sending me a data feed that contains multiple data files like this
|data1|data2|data3|. How can I know where one piece of data starts and stops. Can I use a delimitor, the data file always ends in a ~ ?
Can I send and receive over 1 socket at the same time?
Should I leave the connection open all the time, or close it with each transmission? The client will be connected over a frame relay.
Any resources? I have found several examples where the connections are threaded, but I will only have 1 connection.
I really need to get my brain around the model for this process and can not seem to do it...
rod
|
|
|
|
|
I'm not sure I follow what you mean by threading. First, you mention a case where you want clients processed in multiple threads, but then you mention a single client processing multiple chunks of data. Could you elaborate a little on which you mean?
As far as handling multiple connections, there are a slew of articles here on CP about that so, unless necessary, I won't bog-down the forums with code.
If you want to handle multiple data chunks in a single transaction, think about how several protocols like HTTP deal with it: content-length. You should specify a protocol where the content-length is a fixed size, like a long . That gives the number of raw bytes to read. Read that many bytes. If data exists after that, assume it was another content-length. Keep doing the same thing. Of course, you'll want to check the input data to make sure the protocol was use correctly. This is pretty common in a lot of different things.
You can send and receive on the same socket in a connection protocol. There's some other stuff that has to be done with connectionless protocols since they send datagrams with no return.
As far as leaving the connection open, it really depends on the persistence of communication. If the transactions happen in intervals, you could get away with leaving the connection open. If they transactions are random or you're unsure if another transaction will occur, close the connection.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I'll add another vote for the general solution that Heath already sketched out. In addition, here[^] is some sample code to do exactly this which I posted last week in answer to someone else's question.
To answer your other questions:
Yes, you can read and write on the same socket at the same time.
Leave the connection open, a single connection doesn't consume enough resources to care about. You should, however, be prepared to handle connection failures and go back into listening state to wait for the client to reconnect, incase of transient network failure.
No, you don't need to use multiple threads given that you have a single client. (There is an advanced case where it might be useful to use multiple threads with one client, if you want to send your requests to the mainframe asynchronously, i.e. submit a second request before the result of the first one has been recieved. If your transactional performance is already adequate, then don't complicate life by doing that.)
One last pointer, checksums are your friend:
System.Convert.ToBase64String(<br />
System.Security.Cryptography.SHA1.Create().ComputeHash(<br />
System.Text.Encoding.Unicode.GetBytes(yourData)))
-Blake
|
|
|
|
|
|
I replied only stating that we've had the same, unresolved problem in a different manner indirectly with CDO.
But you're right, the COM forum is dead! I usually try to hop on by and answer a few questions now and then, but mostly some answers require code. Therein likes the problem! Posting sample C/C++ code takes many more lines than various .NET languages (sans MC++, of course!).
I still wonder what happened to friends of COM like Mike Dunn? Nick Parker here at work mentioned he works for PressPlay/Napster now.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
hi...
i made a windows form program...using C#...
this is what i wrote...
using System.Threading;<br />
using System.Windows.Forms;<br />
<br />
class ShowForm<br />
{<br />
public static void Main()<br />
{<br />
Form form = new Form();<br />
<br />
form.Show();<br />
<br />
Thread.Sleep(2500);<br />
<br />
form.Text = "My first Form!";<br />
<br />
Thread.Sleep(2500);<br />
}<br />
} now what happens is a command console apprears then the window appears since i didnt write anything to keep the window there it dissapears..(which is ok,,cause i intended so)
after the window goes off, the console still remains saying
Press any key to continue...
is that supposed to happen??isn't that awkward???is there a way so that the console doesn't come up??
tks for the help....
Have a Super Blessed Day!
-------------------------
For God has not given us a spirit of fear, but of power and of love and of a sound mind.
2 Timothy 1:7
"For God so loved the world that He gave His only begotten Son, that whoever believes in Him should not perish but have everlasting life."
John 3:16
"Therefore you also be ready, for the Son of Man is coming at an hour you do not expet."
Luke 12:40
|
|
|
|
|
On your project properties, change to "Output Type" from "Console Application" to "Windows Application".
Trying to make bits uncopyable is like trying to make water not wet.
-- Bruce Schneier
By the way, dog_spawn isn't a nickname - it is my name with an underscore instead of a space. -- dog_spawn
|
|
|
|
|
tks a lot...
Have a Super Blessed Day!
-------------------------
For God has not given us a spirit of fear, but of power and of love and of a sound mind.
2 Timothy 1:7
"For God so loved the world that He gave His only begotten Son, that whoever believes in Him should not perish but have everlasting life."
John 3:16
"Therefore you also be ready, for the Son of Man is coming at an hour you do not expet."
Luke 12:40
|
|
|
|
|
"(null)" values in datagrid - how to avoid it? (in datagrid or dataset)
One solution is to change SQL query (i.e. NVL function), but it's not comfortable and I don't want to get the solution this way.
Many thanks for answer in advance.
misiek
|
|
|
|
|
You can change your dataset so it automatically changes null for, e.g., an empty string. Every dataset column has the "NullValue" property, check it on the dataset designer by clicking on a string column and pressing F4 to bring up the properties window.
Trying to make bits uncopyable is like trying to make water not wet.
-- Bruce Schneier
By the way, dog_spawn isn't a nickname - it is my name with an underscore instead of a space. -- dog_spawn
|
|
|
|
|
Thanks for your answer.
Unfortunately I don't use any dataset designer.
I use the dataset object only for data visualsation in datagrid.
... <br />
myDataset = new DataSet();<br />
myAdapter.Fill(myDataset); <br />
this.myDatagrid.DataSource = myDataset.Tables[0]; <br />
I've been looking for NullValue property for dataset, but I couldn't find it:
myDataset.NullValue
myDataset.Tables[0].NullValue
myDataset.Tables[0].Columns[0].NullValue
No NullValue property for the objects above exists.
But I've found smtg like this:
<br />
this.myDatagrid.TableStyles[0].GridColumnStyles[0].NullText = "-";<br />
but this kind of error appears:
------------------------------------------------------------------------------
System.ArgumentOutOfRangeException: index was out of range. Must be non-negative or less than the size of the colletion.
Parameter name: index
at System.Collection.ArrayList.get_Item(Int32 index)
at System.Windows.Forms.GridCollumnStylesCollection.get_Item(Int32 index)
at................................
-------------------------------------------------------------------------------
The this.myDatagrid.TableStyles[0] causes the error.
Has anybody got any idea what's wrong?
misiek
|
|
|
|
|
Hi,
There's an option I think in the data grid, or in the drata grid style where you can change the "null" value for the string that you want, sorry now I don't have the code with me, but search for something like "NullText".
HTH
Braulio
|
|
|
|
|
How export Crystal.NET Report to Excel with Box Line in Cell
Example
+-----+------+
| 12 | 123 |
+-----+------+
| 12 | 123 |
+-----+------+
| 12 | 123 |
+-----+------+
Send me small sample to
prof2003@inbox.ru
test
|
|
|
|
|
Hello All!!
I want to write the objects on file. I know how to do this in C++ but i m not geting the equvalent way in .net
e.g pseudocode is like
class MyClass{<br />
int a;<br />
int b;<br />
string c;<br />
}<br />
<br />
MyClass obj = new MyClass();<br />
obj.a=0;<br />
obj.b=1;<br />
obj.c = "can i do this";
In C++ I used to do it like
ofstream out(fileName,ios::binary | ios::trunc); <br />
out.write((char*)obj,sizeof(*obj));
But what is equivalent of ofstream in .net
Thanx in Advance.
sorry for my bad English.
|
|
|
|
|
Not gonna try like I am an expert by an means here but you should look at this article here on Codeproject http://www.codeproject.com/aspnet/fileupload.asp?target=Upload%7CFile[^] about uploading files with ASP.net/C#, I know it sounds off topic but it shows reading in and writing out a file using the FileStream class. Maybe it will help you on the right track?
|
|
|
|
|
Thanx Kluch!!
Well! I can find the overloaded methods to write bytes, strings, integers on files using different streams such as filestream, binarywriter etc but i want to write my custom class object on file, as mentioned in VC++ code in my question. It is quite easy in VC++ and there must be an equivalent function in C# as well. But I coudln't trace it out.
Regards
Farrukh
sorry for my bad English.
|
|
|
|
|
Writing objects into a stream is called "Serialization", C# contains two different foramtters:
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter for binary formatting, and
System.Runtime.Serialization.Formatters.Soap.SoapFormatter for XML formatting.
The SerializableAttribute marks a class as serializable:
[Serializable()]
public class MyClass{
public int a;
public int b;
public string c;
}
To write an object of that class to a file stream, you can use the Serialize-method:
BinaryFormatter formatter = new BinaryFormatter();
FileStream stream = new FileStream(myFileName, FileMode.Create);
formatter.Serialize(stream, obj);
Later you can read teh object from the file with Deserialize():
MyClass obj = (MyClass)formatter.Deserialize(stream);
Itanium wrote:
sorry for my bad English.
Sorry for my even worse English. Have I understood the question, or is this an off-topic posting?
|
|
|
|
|
Thanx John!
101% what i needed.
Reagards
Farrukh
sorry for my bad English.
|
|
|
|
|
Didn't really know what forum to post this in, but I thought this would be as good as any.
What exactly constitues a "command bar"? To me it seems that almost anything can be one; menus, toolbars, popup menus, tabbed interfaces, etc. So what makes something a command bar?
Thanks
- monrobot13
|
|
|
|
|
The term "command bar" typically refers to a component that can act as both a menu and a toolbar. A good example of this is the command bars in the Office suite. Using the Customize dialog, try dragging a built-in menu structure onto a commandbar toolbar. Notice that it becomes a dropdown button. Now drag a menu item onto the toolbar, or a toolbar item onto a menu - they're the same thing.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Is there any chance of Microsoft fixing the problem with inconsistent casing in names of classes, namespaces, enums, what have you? Here's a sampling of things I've noticed lately:
System.Data.DbType
System.Data.DBConcurrencyException
System.Text.Encoding.UTF8
System.Web.Mail.MailMessage.Cc
System.Web.Mail.MailMessage.Bcc
Here's a good place to start reading about Microsoft's preferred casing styles:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconCapitalizationStyles.asp
The guidelines clearly state that two-letter names should be uppercased, but this is inherently flawed because it leads to impossible situations like in the MailMessage class: how to satisfy the naming 'guidelines' but still remain consistent within the class? This two-letter rule is nutso. (I think that the designers of the MailMessage class did a good thing by being consistent within the class, though.)
Does this bother anyone but me? I don't mind adapting to ANY convention, but it makes it a headache when there is no clear convention in actual practice, and you have to integrate with or extend an existing API.
Thank you.
Jeff Varszegi
|
|
|
|