Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Web Service

Status
Not open for further replies.

Ladyhawk

Programmer
Jan 22, 2002
534
AU
I posted this in the VB.NET forum but didn;t get any response so I thought I would post it here.

I am currently writing a web service which will update a database which is on the web server. How do I connect to the database... I can't seem to give the connection object a url. The database is located in the same directory as the web service dll but how do I find out that directory in code?



Ladyhawk. [idea]
** ASP/VB/Java Programmer **
 
You shouldn't be specifying a URL for the connection. Just do your connection as you would any other time. Specifying the normal connection string should work just fine.

What type of DB are you running? Are you connecting to it anywhere else, if so, how did you do it there?

________________________________________
Michael C Flanakin
Indigo Web Systems
michael.flanakin@indigows.com
 
Writing a web service should be just like writing any other .net app, you just make some of the methods WebMethods.

If you are using SQL Server, just make a new SqlConnection object
Code:
dim myConnection As new SqlConnection("my connection string")
(sorry, if my VB is poor)

Do that in your WebMethod. Put your connection string in a web.config file in the directory the root of your app and get it using System.Configuration.ConfigurationSettings.AppSettings("yourConnectionStringKey") if you want.

Hopefully this helps.

[pipe]
 
This is the code I am using...

Dim objOleConn As OleDb.OleDbConnection = New OleDb.OleDbConnection()

With objOleConn
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source= C:\Inetpub\ .Open()
End With

Dim cOLE As OleDb.OleDbCommand = New OleDb.OleDbCommand _
("INSERT INTO table1 (test) VALUES ('jjjj')", objOleConn)
cOLE.ExecuteNonQuery()

I didn't really want to hard code the path. I just wanted it to be whereever the dll was. But that's ok. I am getting a weird error when I try to execute the insert command - Operation must use an updateable query.

The insert statement works fine in Access.

What's going on?


Ladyhawk. [idea]
** ASP/VB/Java Programmer **
 
The exact same code works fine when run from a normal windows application but not in a web service. Why?

Ladyhawk. [idea]
** ASP/VB/Java Programmer **
 
"Operation must use an updateable query" when it tries to run the Insert statement

Ladyhawk. [idea]
** ASP/VB/Java Programmer **
 
Make sure the web user(s) have access to the file. Do they? Remember, they need access to modify it, not just read it.

________________________________________
Michael C Flanakin
Indigo Web Systems
michael.flanakin@indigows.com
 
How do I give them access to modify the database?

Ladyhawk. [idea]
** ASP/VB/Java Programmer **
 
Right click the database file and go to properties. Select the Security tab. Select the IUSR_xxx username. This is what accesses the file via code. In the bottom, make sure the Modify permission is allowed. If you have an ASP.NET user of some kind, ensure this one has the same permissions set.

Try this, and if that does not work, then allow the user(s) modify permission on the directory. Honestly, you might want to move the database out of that directory. Not that it would happen, but if you give your web user permissions to the DLL folder, someone MIGHT be able to hack into the DLLs. I don't expect that to happen, but it's all about making sure they don't have the chance.

________________________________________
Michael C Flanakin
Indigo Web Systems
michael.flanakin@indigows.com
 
I don't have a Security tab. I am running this on XP using the localhost web server.

Ladyhawk. [idea]
** ASP/VB/Java Programmer **
 
Are you an admin? I'm on XP as well. I would guess that you're not set as an admin on the box.

Try this...

1. Goto Start | Settings | Control Panel | User Accounts
2. Double click your username
3. Set the Other drop down list to Administrators
4. Click OK, OK, and then you will be asked to logoff.

If you can't get to step 2 or 3, then you're not an admin. You'll need to find out who has the admin password and have that changed. Sometimes the default admin password is "P@$$word1".

________________________________________
Michael C Flanakin
Indigo Web Systems
michael.flanakin@indigows.com
 
I am an administrator of the machine.

Ladyhawk. [idea]
** ASP/VB/Java Programmer **
 
My IT support person thought that, being a developer I didn't need to see the security tab on files so he set the Use Simple File Sharing setting in the folder options. I now have a security tab and have fixed the problem. My IT support guy seems to enjoy turning off particular features of XP (because in his option you don't need them) and not telling anyone.

Thanks to everyone for their help.

Ladyhawk. [idea]
** ASP/VB/Java Programmer **
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top