command line to create data source with sql authentication? - sql-server-2005

I'm looking to run a batch file on windows xp professional which creates a system odbc data source for a sql server connection. I can do that with:
ODBCCONF.exe CONFIGSYSDSN "SQL Server" "DSN=Kappa| Description=Kappa Data Source | SERVER=10.100.1.10 | Trusted_Connection=Yes | Database=subscribers"
However I need a way to set the sql server authentication to be "With SQL Server authentication using a login ID and password entered by the user." to be set and preset the login id and pass.
Any ideas on how to do this?
thanks in advance

I hope this helps someone, i found that i could not store the username and password. However, I was able to make a ODBC connection without those. The problem was that the connection kept returning an error about how it could not locate the data source name or driver. Only after I removed the spaces from the attribute string could my programs use the odbc connection.
So
ODBCCONF.exe /a { CONFIGSYSDSN "SQL Server" "DSN=dsnname | SERVER=yourservername | Database=Finance"}
should become
ODBCCONF.exe /a { CONFIGSYSDSN "SQL Server" "DSN=dsnname|SERVER=yourservername|Database=Finance"}

create a .reg file with the parameters and merge it in with regedit.exe
Tip: export an existing ODBC profile from the registry to help get the syntax and field names correct

ODBCConf ConfigSysDSN "SQL Server" "DSN=xxxxx|SERVER=yyyyy|Trusted_Connection=No"
seemed to work for me.

You create the DSN the same way for both trusted and non trusted. It is when you use the ODBC connection string that you specify that you want to use trusted connections.
DsnString = "ODBC;DSN=Kappa;Database=MyDBName;Integrated Security=SSPI;Trusted_Connection=True"

Related

How to Connect to SQL from R Studio

I use Microsoft SQL Server Management Studio on Windows 10 to connect to the following database and this is what the login screen looks like:
Server Type: Database Engine
Server Name: sqlmiprod.b298745190e.database.windows.net
Authentication: SQL Server Authentication
Login: my_user_id
Password: my_password
This recent R Studio article offers an easy way to connect to SQL Servers from R Studio using the following:
con <- DBI::dbConnect(odbc::odbc(),
Driver = "[your driver's name]",
Server = "[your server's path]",
Database = "[your database's name]",
UID = rstudioapi::askForPassword("Database user"),
PWD = rstudioapi::askForPassword("Database password"),
Port = 1433)
I have two questions
What should I use as "[your driver's name]"?
What should I use as "[your database's name]"?
The server path I'll use is sqlmiprod.b298745190e.database.windows.net (from above) and I'll leave the port at 1433. If that's wrong please let me know.
Driver
From #Zaynul's comment and my own experience, the driver field is a text string with the name of the ODBC driver. This answer contains more details on this.
You probably want someting like:
Driver = 'ODBC Driver 17 for SQL Server' (from #Zaynul's comment)
Driver = 'ODBC Driver 11 for SQL Server' (from my own context)
Database
The default database you want to connect to. Roughly equivalent to starting an SQL script with
USE my_database
GO
If all your work will be within a single database then puts its name here.
In some contexts you should be able to leave this blank, but you then have to use the in_schema command to add the database name every time you connect to a table.
If you are working across multiple databases, I recommend putting the name of one database in, and then using the in_schema command to specify the database at every point of connection.
Example using the in_schema command (more details):
df = tbl(con, from = in_schema('database.schema', 'table'))
Though I have not tried it, if you do not have a schema then
df = tbl(con, from = in_schema('database', 'table'))
Should also work (I've been using this hack without issue for a while).

Can I access an encrypted SQL Server Compact database in Excel VBA?

I want to access an encrypted SQL Server Compact Edition database via VBA. I can access the database fine when it is not encrypted, but the code breaks when I try to use a password:
pConn.ConnectionString = "PROVIDER=Microsoft.SQLSERVER.CE.OLEDB.3.5;Password=[my_password];Data Source=" & SdfPath
I've been following the connection string example provided here for SQL Server Compact with a password:
Encryption enabled
Use this connection string to enable encryption on the database.
Data Source=MyData.sdf;Encrypt Database=True;Password=myPassword;
File Mode=shared read;Persist Security Info=False;
The Encrypt Database="True" pair is really not necessary as the presence of the Password-parameter itself turns on encryption for the connection.
But why doesn't this work in Excel VBA 2010?
Apparently, the connection string example in the site I was using is incorrect. I found the correct connection string example from Microsoft:
Using Microsoft ActiveX® Data Objects for Windows CE (ADOCE), Microsoft ActiveX Data Objects Extensions for Data Definition Language (DDL) and Security (ADOXCE), or the Replication object
To create a password-protected database using the either the ADOCE or ADOXCE Catalog object, or the AddSubscription method of the SQL Server CE Replication ActiveX object, you must specify the provider-specific SSCE:Database Password connection property in the connection string. For example:
"Provider=Microsoft.SQLSERVER.OLEDB.CE.2.0; data source=\NorthWind.sdf; SSCE:Database Password=[myPassword]"
And so now my code is:
pConn.ConnectionString = "PROVIDER=Microsoft.SQLSERVER.CE.OLEDB.3.5;SSCE:Database Password=[my_password];Data Source=" & SdfPath
This worked perfectly for me.
If you have SQL Server Compact 4.0 installed and use "Microsoft.SQLSERVER.CE.OLEDB.2.0" or "Microsoft.SQLSERVER.CE.OLEDB.3.5" as provider in connection string, you will get an error mentioning provider not found. Change connection string to reflect to "Microsoft.SQLSERVER.CE.OLEDB.4.0".

" keyword not supported 'file access retry timeout' " when creating a new SQL server compact database?

I am receiving the following error when I try to create a new SQL Server Compact Database using the Server Explorer. "Keyword not Supported 'file access retry timeout'.
I am following the instructions from the following page keyword not supported http://msdn.microsoft.com/en-us/library/aa983322.aspx
The error occurs during step number 6.
In the textbox where it says "Enter the new SQL Server Compact Database FileName "; No matter what file name I enter and what path I provide, I get that error.
for example. D:\MySQLDB
The error comes.
Why is this happening and what should I do to fix this ?
Any help will be appreciated.
You need to install SQL Server Compact 4 SP1, as the mentioned keyword was introduced with this Service Pack

dbext connection string for sql-server

I have dbext installed into gVim - the plugin menu is visible and the help file are accessible; just not helping at the moment!
Suspect it is a connection string problem. I have the following in _vimrc:
" Microsoft SQL Server
let g:dbext_default_profile_WH = 'type=SQLSRV:user=profileName:passwd=profilePassword:dsnname=SQLOLEDB.1:srvname=imsname'
Is this correct?: dsnname=SQLOLEDB.1
Here is my working connection string configuration
let g:dbext_default_profile_mydb = 'type=SQLSRV:user=sa:passwd=password:srvname=localhost\SQLEXPRESS:dbname=mydb'
It seems that only difference between two configuration strings DNS part so it might be DNS problem as you mentioned.

Oracle database connection string PLSQL compatibility

I'm using an application called Logi info. it requires a connection string to my oracle database. the connection works fine but in order to configure the connection to recive ref cursors from the database, I apparently need to add PLSQLRSet=1 to the end of the string. when I do that I recieve an error "invalid connection string"
Here is my connection string without plsqlrset=1
Data Source=SID; User Id=username; Password=password;
My concern is that PLSQLRSet=1 might be .NET paramater only. Can anyone shed some light on the issue.
Thanks
It appears that the PLSQLRset option is a feature of the OraOLEDB provider (per http://download.oracle.com/docs/cd/B10501_01/win.920/a95498/using.htm).
Therefore I would guess that you have to add Provider=OraOLEDB.Oracle to the connect string -- as shown in the screenshot on the page you linked to -- in order to use this option.