|
I suspect that the user account that your ASP page is running under - typically IUSR_machinename - doesn't have NTFS write permissions to the directory that contains the .MDB file. Hence the database is opened read-only and you can't insert new rows or update or delete existing ones.
The account needs to be able to write to the directory, not just the file, as the Jet database engine needs to create an .ldb file if multiple connections access the file concurrently.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
I normally do like this..
if exists ( select * from Table1 )<br />
begin<br />
...<br />
end
But now I don't know Table1 until runtime so I did
declare @sql nvarchar(50)<br />
set @sql = 'Select * from'+@Table <br />
if exists ( exec (@sql) )
How can I achieve last line of code?? It is not working? How can I check the condition?
|
|
|
|
|
You can use the @@ROWCOUNT value to see if any row exists (@@ROWCOUNT <> 0 ). If you need to know if the table exists, I suggest you use the sysobjects table to see if the table exists. Here's a simple example:
<br />
<br />
DECLARE @sql varchar(50)<br />
DECLARE @table varchar(50)<br />
SET @table = 'Employees'<br />
SET @sql = 'SELECT * FROM '+ @table<br />
<br />
IF EXISTS(SELECT * FROM sysobjects WHERE [name] = @table AND xtype = 'U')<br />
BEGIN<br />
EXEC (@sql)<br />
IF @@ROWCOUNT <> 0<br />
BEGIN<br />
PRINT 'DATA FOUND!'<br />
END<br />
END<br />
Hope this helps!
~javier lozano
(blog)
|
|
|
|
|
It isn't something SQL is very good at and the answer, at least as best as I can find it, is not pretty.
DECLARE @result int
DECLARE @sql nvarchar(500)
SET @sql = 'IF EXISTS(SELECT * FROM '+@Table+
') SELECT 1 AS Result ELSE SELECT 0 AS Result';
CREATE TABLE #Result (Result int)
INSERT INTO #Result
EXEC(@sql)
SELECT @result = Result FROM #Result
IF @result = 1
BEGIN
-- This code is run if there are existing records in @table
END
DISCLAIMER: I typed this directly into Code Project, there may be errors
[EDIT]
Actually, after seeing Javier's solution I think that his is better on security grounds as it also helps protect against secondary sql injection attacks. Although, I would say that if your table contains a lot of rows then it would be slower as Javier's solution is returning all the rows in the table out of the Stored Procedure it is contained within in order to work out the number of rows.
[/EDIT]
Do you want to know more?
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and Forums
|
|
|
|
|
Hi,
I would like to know how I can add/read user-defined properties to an MS Access DB using ADO.NET. I need to add a property such as version.
In DAO, one could do that using the "CreateProperty()" function, but here I'm stumped.
Thanks!
|
|
|
|
|
Hello
I think it's possible to export a .Net dll and use it from unmanaged code, using the utility tlbexp.exe, or regasm.exe, that export and registers it.
I'm trying to export System.Data.dll, that contains the most part of ADO.net, in order to use it in a MFC application. So, I do:
regasm /verbose /tlb:systemdata.tlb "c:\....\System.Data.dll"
but, it answers:
type SQLDebbuging was exported.
Why only SQLDebbuging type is exported? What happens with all the others?
Is there any way to use ADO.NET from unmanaged code?
Thank you very much for your help.
|
|
|
|
|
Hi, now I have a big trouble in vb.net and access. I have one table call tblTest with the following field:
ID Name
N01 Kagna
N02 Bopha
When I run the following SQL statement in access query: SELECT * FROM tblTest WHERE tblTest.ID LIKE 'N*' then the result return both row. But when I run the same SQL statement from VB.NET it did not return any row. But if I run the following SQL statement SELECT * FROM tblTest WHERE tblTest.ID LIKE 'N01' from VB.NET then it return 1 result (the N01). I don't what is the problem that cause in VB.NET, I really in a difficult situation now because the result did not return as what I expected. Here is my code:
Dim cnnSearch As New ADODB.Connection
Dim rstCat As New ADODB.Recordset
With cnnSearch
.Open(strConnection)
.CursorLocation = ADODB.CursorLocationEnum.adUseClient
End With
rstCat.Open("SELECT * FROM tblTest WHERE tblTest.ID LIKE 'N*'", cnnSearch, _
ADODB.CursorTypeEnum.adOpenKeyset, _
ADODB.LockTypeEnum.adLockOptimistic)
Note: I'm using VB.Net and connect to database using ADODB.
A thousand mile of journey, begin with the first step.
APO-CEDC
Save Children Norway-Cambodia Office
|
|
|
|
|
You could try the MS-SQL syntax, and use % instead of *:
SELECT * FROM tblTest WHERE tblTest.ID LIKE 'N%'
Wout Louwers
|
|
|
|
|
I also try to use it, but it is not working. But as far as I know use % if we working with SQL server. But in this case I use Ms access so I have to use * instead of %. What I wonder is the same statement in Ms access is working while in vb.net is not working... Until now what I suspect is because I did not use ADO.NET in VB.NET. I use COM technology by adding the reference from the COM tab of Add new reference dialog. As the code above, if I use in vb6 is working fine, may be I have to test ADO.NET in vb.net make sure it is working or not.
A thousand mile of journey, begin with the first step.
APO-CEDC
Save Children Norway-Cambodia Office
|
|
|
|
|
Many thankkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk Now it is working with your suggestion. Thankkkkkkkkkkkk alottttttttttttttt
A thousand mile of journey, begin with the first step.
APO-CEDC
Save Children Norway-Cambodia Office
|
|
|
|
|
I don't know if anyone here can help me, I have a working application that uses an ODBC connection to retrieve data from a CSV file.
The only problem I have is that it always treats the first line as Column Names but our company gets sent data from different sources, some include Column Names, others don't.
I would like to make the application more flexible and enable it to work with either format files without having to write a schema.ini file for each import.
The connection string is something like:
<br />
"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=C:\MyTest;"<br />
Can the connection string be changed to indicate if column info is not included?
Regards
Wayne Phipps
____________
Time is the greatest teacher... unfortunately, it kills all of its students
LearnVisualStudio.Net
|
|
|
|
|
Friends,
I am using MS Access for the first time. Before that,i used SQL-server. The problem is that, in SQL-server, i always ran an insert query successfully. But this query is not running in Access. Letme explain the problem.
In SQL server i have a simple table "Students" with fields 'id', 'StudentName', 'FatherName'. The 'id' field is primary key and is set to "Auto Increment". Now if i need to insert a row in this table i don't need to supply the value of id (if it is set to Auto increment). I always successfully used following query to insert row in this table:
insert into Students values ("Bill", "Gates");
So far so good. Now i have same scenario in MS-Access, same table, same fields and similarly 'id' field is of type "Auto Number". Now, whenever i run the insert query wrote above, MS-Access gives me error that i've not supplied complete arguments. Yes, if i manually give the value of "id" field, the query runs successsfully.
Please tell me how to get rid of manually giving of id value in case of MS-Access.
Imtiaz
|
|
|
|
|
You need to specify the names of fields being inserted:
Insert into Students ([StudentName],[FatherName]) values ("Bill", "Gates");
Why would anyone waste time arguing with an accountant about anything? Their sole function is to record what happenned, and any higher aspirations are mere delusions of grandeur. On the ladder of productive contributions they are the little rubber pads at the bottom that keep the thing from sliding out from under you. - Roger Wright
|
|
|
|
|
how could we use the ado event while using VC6.0?
please give a exsample if possible
|
|
|
|
|
Hello,
I want to use crystalReport10 in my VC++ app.
But after instert it shows me a white paper only,
Can any one help me?
Happy Christmas.
Thanks.
|
|
|
|
|
Hi friends,
I am working on a project where i have to run following code int Sql Server 2000
declare @v int
declare @tab_name char(15)
set @tab_name = 'Employee_master'
declare @str varchar(50)
set @v=exec('select empid from '+@tab_name+' where empid = 6 ')
after getting value of employeeid i have to perform some task. So i want that empid value in variable @v
another solution i found make temparory table and then insert that value in table and then retrive again in variable @v.
But it is very logn step and it make my query heavy coz i have to perform more task after that.
Is there any solution to retrive that exec(------) value in @v variable
Thank You Very much for reading my request
Hemant Mane
|
|
|
|
|
I have my category hiearchy stored within a table called categories. What I need to do is display the actual category hiearchy with a single sql statement.
For example:
I have the following data in the table
category | category_no | category_above
---------------------------------------------------
Computers | 1 | 0
Dell | 24 | 1
Sony | 48 | 1
Pentium 4 | 33 | 24
Pentium 4 | 85 | 48
How would i query a database to sort the records as follows (in the category hierarchy)?
Computers, Dell, Pentium 4, Sony, Pentium 4
so i could then generate text that looks like
Computers
-->Dell
----->Pentium 4
-->Sony
----->Pentium 4
Anyone have any ideas? Right now I have a function that loops through, but the problem is it's using too many resources...I have to open a database connection each time i loop through. So if I had 500 categories i'd be opening 500 database connections, which i don't want.
Any help?
|
|
|
|
|
Try to normalize yout category table. That will be a better solution for this.
Once you normalize, you can show the data in hierarchy. Then use Datarelation to show the data.
Sreejith Nair
[ My Articles ]
|
|
|
|
|
Can you please explain a little further and give me an example...
How would it work say if I had two tables:
If the first table would carry the top level categories (Main) and the second table would then keep the sub level categories...how would that benefit me? I want to make sure that I don't limit the users from creating category levels.
|
|
|
|
|
Try to use DataRelation class for further reference.
Sreejith Nair
[ My Articles ]
|
|
|
|
|
hi,
while connecting in the local machine there no porblem in the connection string. while connecting to the sql server from another machine through network. i got error of "login failed to uesr null". Sql Server is Windows authentication. Connection string is given below. what's the change need in connection string or sql server. bother machines are windows 2000. any one help to me.
strConnectionString = "Integrated Security=SSPI; Persist Security Info=False;Initial Catalog=atc;Data Source=" + m_strServer + ";User ID=sa; Password=;";
Have A Nice Day!
Murali.M
|
|
|
|
|
If you are using Windows authentication then you'll need something like
"Data Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI;"
You don't need the UserID and Password field
For more connection string help, this site[^] is all you need.
Michael
CP Blog [^]
|
|
|
|
|
To add to what Michael said, if you are connecting from another machine you will have to make sure that the user account exists on both machines with the same password. On a small network, like a home network, this isn't too difficult to manage. However on a corporate network this is not manageable and you should look into using Domain accounts for this (the connection string is the same as for local machine accounts, it is just that the account information resides on a domain server somewhere on your network)
Does this help?
Do you want to know more?
WDevs.com - Member's Software Directories, Blogs, FTP, Mail and Forums
|
|
|
|
|
I actually have the same problem but im a compleate beginner so i will ask a stupid question.
How can user account matter if I use windows authetication? Would it be more simple just to skip the authitication and use username and password?
And one more beginners question, what is a Domain account
Hope somebody bothers to anserw
Regards Johan
|
|
|
|
|
Johan finland2 wrote:
How can user account matter if I use windows authetication?
It has to authenticate against an account in windows. Regardless of how you connect there will be an account involved. With SQL authentication you have to specify the account and password in the connection string, with Windows Authentication the operating system will provided the authentication on behalf of the SQL Server.
Johan finland2 wrote:
Would it be more simple just to skip the authitication and use username and password?
I don't understand your question. Authentication is the process of verifying that a user is who they say they are. SQL Server has build in authentication which is useful if people are connecting from non-windows machines. If you are connecting from a windows machine you can let windows provided the authentication details to SQL Server on your behalf by virtue of the fact that you must have passed through some authentication to log on to windows itself.
Johan finland2 wrote:
what is a Domain account
A domain account is an account on a central server. This allows a user to log into any machine within the domain (typically a LAN). This means that the account information is held in a central location and does not have to be repeated on each machine within the network.
Does this help?
Do you want to know more?
WDevs.com - Member's Software Directories, Blogs, FTP, Mail and Forums
|
|
|
|