in reply to Data base connection error

mhoang:

You mention that you're using Windows authentication ... is the webserver running under account that has DB privileges?

...roboticus

Replies are listed 'Best First'.
Re^2: Data base connection error
by mhoang (Acolyte) on Aug 27, 2009 at 00:16 UTC

    I changed to sql server authentication now, I set up myself as the sysadmin for sql server. Do you think i have missed something esle? Is the connection correct now? my $db = new Win32::ODBC("DSN=portal-mk2", username="mhoang", password="test");?

      mhoang:

      I can't really tell. You just don't provide much information to work with.

      DSN configuration

      Part of the problem is that you're using a DSN to connect, and that hides a lot of information. With just a DSN name, I don't know a thing about your data source configuration. I try to avoid using DSNs and instead spell out the details for each connection, but that's just a personal preference. If you're going to use a DSN to connect to SQL server, though, you need to know a few things. For example, what sort of DSN is it? I'd suggest using a System DSN if you have a choice. If it's a User DSN, then you have to make sure you set up the DSN for the account the web server runs in in exactly the same way as the DSN on your account.

      Which ODBC driver does the DSN use? The SQL Native Client might be pretty good, but I've been using the SQL Server driver (v 2000.85.1132.00) for the past few years, and it works well connecting to SQL Server 2005. So just to debug your connection, I'd try using that one. Once you resolve your connection issues, you can then try moving to a different driver, if desired.

      I use the DBI module with DBD::ODBC and other modules to access databases, so I have no experience with Win32::ODBC, so if it has any quirks, you'll either have to delve into the documentation, or perhaps someone else might mention them.

      Error details

      The next part of the problem is that you don't specify the way that it doesn't work. Error messages are sort of handy. Normally they tell you what the problem is. So if you don't tell us the exact text of the error message, we don't know where to start looking for problems. For all we know, you could be using a command line on one computer and the script running on another computer with a different configuration, etc.

      ...roboticus

        Thank you for all responses i have figured out the reason. I think i should post here so it will save time for someone else later. The reason is i did not create the user in the sql server i thought that if i give myself the administrator right then i should not have any problem to connect to server. However as i use the system DSN so when it connects to sql server it use the IUSR user instead of me. So to fix that just create IUSR user account in sql server