Simple method to test system DSN's? - odbc

Is there a simple way to test that a System DSN setup on Windows Server 2000/3 is configured and connects properly? ODBC Data Source Administrator doesn't appear to have anything for this.

As Serapth suggested there is a test button in the last wizard step of ODBC data source administrator that will help you test the connectivity to the database. If you are looking for an easy way & would like to eliminate going through all those wizard steps, you may use the following vb script. However, be warned, this script requires the DSN to be configured with trusted connection. Also, this script was tested only with MSSQL server.
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
objConnection.Open "DSN=YOUR_DSN;"
objRecordset.CursorLocation = adUseClient
objRecordset.Open "SELECT count(*) FROM YOUR_TABLE_NAME" , objConnection, _
adOpenStatic, adLockOptimistic
objRecordSet.MoveFirst
Wscript.Echo objRecordSet.RecordCount
objRecordset.Close
objConnection.Close
Please refer to Microsoft's technet site for more scripting samples.

As crude as it is, I always just used the ODBC Connection in the Control Panel. On the final page of the setup wizard there is a "test Connection" button.
EDIT: Just re-read your question and realized we are referring to the same control panel applet. Yes, there is the ability to test a system DSN connection using the ODBC Data Source Administrator. Edit Connection, next through all the windows and the final screen will have a Test Connection option.

Related

SQL works in R studio but not in R-Serivces

This code works perfectly in R-Studio but there is no way to make it work in MS Management studio. It keeps on saying that:
[Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'myserver\LOCAL01'.
That is not my user give it is a trusted connection. Can someone help me understand it?
ALTER PROCEDURE [dbo].[TESTIM] AS
BEGIN
SET LANGUAGE ENGLISH
CHECKPOINT 
DBCC DROPCLEANBUFFERS
EXEC sp_execute_external_script
#language = N'R'
, #script = N'
con <- "Server=myserver\\LOCAL;Database=mydb;Trusted_Connection=true";
sql <- RxInSqlServer(connectionString = con, shareDir = "c:\\TMP");
local <- RxLocalSeq(sql);
rxSetComputeContext(local)
ff <- RxSqlServerData(sqlQuery = "select top 1 * from mytable", connectionString = con);
t = rxImport(ff);
OutputDataSet <- data.frame(SUCCESS = TRUE);
'
WITH RESULT SETS (([SUCCESS] BIT))
END
So, when you execute sp_execute_external_script it executes under one of 20 Windows user accounts (worker accounts) that has been created during installation of SQL Server R Services. These accounts are created for the purpose of running tasks under a security token belonging to the SQL Server Trusted Launchpad service.
This works very well, but if you need to create a SQL connection inside your R script (as in your case) and you use trusted connection (Windows Authentication), you are executing under the user account mentioned above ('myserver\LOCAL01' in your case), and that account need to be given permission to log in to the SQL Server instance on your behalf.
To do this:
In SQL Server Management Studio, in Object Explorer, expand Security, right-click Logins, and select New Login.
In the Login - New dialog box, click Search.
Click Object Types and select Groups. Deselect everything else.
In Enter the object name to select, type SQLRUserGroup and click Check Names.
The name of the local group associated with the instance's Launchpad service should resolve to something like instancename\SQLRUserGroup. Click OK.
By default, the login is assigned to the public role and has permission to connect to the database engine.
Click OK.
That should do it (the above steps are copied from here.
If you want to read more about the user accounts you can have a look at my blog-post "Microsoft SQL Server R Services - Internals III".
Hope this helps!
Niels

Sql Express Connection in ASP

I am trying to connect to sql express db and inserting record to one of the table inside it using following code.
set conn=Server.CreateObject("ADODB.Connection")
SQL_Conn_STRING = "Driver={SQL Server};Server=(local);Database=classic_asp_poc;uid=my-domain\username;pwd=my password"
conn.Open SQL_Conn_STRING
Response.Write("con open")
I am getting error on open connection. Is there any problem in my connection string?
If you're using mssql express, you need to add \SQLEXPRESS to your database address/ip, so in your example you would use Server=(local\SQLEXPRESS)
You're using an odbc connection string. OLEDB or native client strings are the preferred method eg
SQL_Conn_STRING = "Provider=sqloledb;Data Source=local\SQLEXPRESS;Initial Catalog=classic_asp_poc;User Id=my-domain\username;Password=my password"
See this easy to remember link for more examples
http://www.connectionstrings.com/sql-server/

dynamics AX batch job through ODBC

I have problems with an ODBC connection used in a batch job: when executed, I have the following error message :
"The ODBC operation failed.Unable to connect to database
Invalid connection String attribute Trusted_Connection
Unabe to create object 'OdbcConnection' "
I try to connect to an Access database, I use the following code:
LoginProperty loginProperty;
OdbcConnection odbcConnection;
;
loginProperty = new LoginProperty();
loginProperty.setDSN("MyDSN");
loginProperty.setDatabase("MyDatabase");
odbcConnection = new OdbcConnection(loginProperty);
when debugging, it crashes on odbcConnection = new OdbcConnection(loginProperty). I tested the same code in a job in local client execution, there was no problem and it worked fine(without defining login password in code or DSN). My DSN seems to be OK on AOS, I'm using AX 2009 without SP1, I saw some examples where there was login/password defined in loginProperty object , the setUserName() and setPassword() methods are not available in my AX version loginProperty object. My class is executed on server-side (as any batch job).
Is there some particular setup to do to connect to ODBC datasource through batch job?
any ideas or suggestions?
thanks for your help
Edit:AOS is running on Windows server 2003 32 bits, ODBC tested on it, works fine but doesn't work in AX through batch job
Most likely you will need a 32-bit DSN connection for your AX. I would create both versions on the AOS server.
Look here for details.
It may be caused due to permisions. "trusted connection" refers to the fact that you connect to the database through the user logged to the current session. When you run a Job from the AX client, this is executed with the user that runs the current AX client (the one logged to the active session); When code is executed from server in a batch job, code is executed through the user that runs the AOS windows service.
Has this user permissions to read/write/access the access file and directory?
If you are on a 64 bit machine use C:\Windows\SysWOW64\odbca32.exe to create the datasource.
Check under which ID the AOS runs, log on with that ID and make sure you can 'see' the data source.
Also make sure that the AOS account has access to the directory/files (if using file-based odbc)

Provider error '80004005' Unspecified error

I know this question has been asked before but i can't seem to see from the other posts what this could be i don't know asp i have just been uploading images and changing the database and re uploading via FTP but now i have come across a error
Provider error '80004005'
Unspecified error
/Includes/DB/DatabaseConnect.asp, line 8
<%
Dim espostiDB
Set espostiDB = Server.CreateObject("ADODB.Connection")
'espostiDB.ConnectionString = "DSN=esposti.dsn"
'espostiDB.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db\esposti1.mdb")
espostiDB.ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("db\esposti.mdb") ')e:\inetpub\wwwroot\esposti\esposti.mdb"
'espostiDB.ConnectionString = "DSN=esposti.dsn"
espostiDB.Open
%>
line 8 is espostiDB.open
Database is Access 2000
Help Much appreciated
Jack
This is how I solved this problem, the exact same error. Went to Control Panel - Administrative Tools - Internet information Services. On the right click View Application Pools and for both "Classic NET AppPool" and "DefaultAppPool" set v4.0 network framework version. If it's set to v2.0 the error above will show up.
Working with your code above, you could use this:
<%
Set espostiDB = Server.CreateObject("ADODB.Connection")
connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("~\db\esposti.mdb")
espostiDB.Open connStr
%>
The info here will also give you some pointers of how to work Server.MapPath (in case your mdb file is not in the root of your website).
80004005 errors can be numerous things, one thing to check is that the database is not currently in an open state and therefore locked, so every time you open a connection you need to make sure that you close it. An easy way to check this is to check if there is an Access lock file (.ldb) file in the same folder as the database.
Check that you've not inadvertently changed the path so it's now incorrect (a Response.Write(Server.MapPath("db\esposti.mdb"))) should print the full path.
Also, worth recycling the IIS app pool, sometimes connections remain open in IIS and the database becomes unresponsive, this can be a sign you're not closing connections properly.
The cause of this conflicts looks to be 32 Bit Application running on the 64 Bit. Please make sure that the ODBC connection is described at C:\Windows\SysWOW64\odbcad32.exe

Cannot open database 'dbname' requested by the login. The login failed

Firstly, I know that there are a lot of similar topics, but none seem to solve my problem.
I have inherited a project where the front-end is built in ASP.NET and the CMS is built in classic ASP. I'm in the process of setting up a local development environment where I've copied the database from the live server and am configuring the website to connect to my new local DB.
The ASP.NET part is connecting with the connection string Data Source=.\\SQLEXPRESS; Database=DBNAME; Trusted_Connection=True; but I had to mess about with Application Pools and Permissions.
I'm having a problem with getting the classic ASP part of the website to connect to the SQL database. The error I am recieving is:
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot open database "DBNAME" requested by the login. The login failed.
/cms/connections/Conn.asp, line 18
The code in that file is:
12. Dim Conn_STRING, URL, mailHost
13. Conn_STRING = "Driver={SQL Server}; Server=.\SQLEXPRESS; Database=DBNAME; Trusted_Connection=True;"
15. Dim conn
16. set conn = Server.CreateObject("ADODB.Connection")
17. conn.ConnectionString = Conn_STRING
18. conn.Open
I know it's a permission problem or some sort, but I can't get to the bottom of it. I'll appreciate any help at all :)
hmmmm, well, the asp.net part is using SQLExpress, connected via an attached file. DBNAME in the first example is going to refer to a db file name in the actual asp.net project. It's been quite a long time since I last used classic ASP, but I'd be STUNNED if it supports this. You need to attach the db file to an actual sql server and use it that way.
server=mycomputername\sqlexpress; database=DBNAME; user id=username; password=password
You'll need to open your database in sql express mngmt studio
http://www.microsoft.com/download/en/details.aspx?id=7593
Go into your security settings for that user and set the default database to "dbname" (whatver your real dbname is of course)
Ensure your app pool is set to run under the user that has permissions to that database. It may just be easier to enable mixed mode authentication and create a sql user to connect to the database rather than messing around with windows authentication on an app pool.
You wil lof course need to change your connection string then to support the sql authentication if you go that route.
http://msdn.microsoft.com/en-us/library/ms143705%28v=sql.90%29.aspx

Resources