Notifications
Clear all

[Closed] Connecting to SQL database

I’ve been looking through the threads and found many queues on how to connect to MySQL but none so far who connect to SQL (SQL server 2005).
Been trying a lot of things but I seem to be unable to establish a connection from within Max.

Anyone had a successfull attempt at this yet?

Thanks!
Tom

5 Replies
1 Reply
(@rustyknight)
Joined: 11 months ago

Posts: 0

What have you tried?? Python? .Net? What are you using? Max 8, 9…??

Shane

I’d need the connection through MaxScript (using Max 2008). I’ve tried what’s in the help file and the variations that can be found for MySQL on the forum … but none worked so far.
I hoped someone got a successfull connection and point out where the problem might be. Is it in the code? Are there specific drivers to be used, special connections to be setup or activated in windows …
I can login and work in the DB from the SQL managment client on my computer, so the DB is accessible. No trying to get the connection in Max …

Example of the code I tried and what the listener said : (I tried more stuff but consider them irrelevant)

 
DogConn = createOLEObject "ADODB.Connection" 
DogConn.Open "driver={SQL Server}; server= ServerIPAdress; database=DBName"
Return : 
<OLEObject:ADODB.Connection>
-- Runtime error: OLEObject method call failed: 
Error Message 1: Provider is not specified and there is no designated default provider.

or also
 
DogConn = createOLEObject "ADODB.Connection" 
DogConn.Open "provider=SQLOLEDB.1;Data Source= ServerIPAdress; user:xxx; password:xxx"
-- with many variations and other fields like "initial Catalog", anyway, I get the same return if I cut the string short at "provider=..."
 
Return :
 
<OLEObject:ADODB.Connection>
-- Runtime error: OLEObject method call failed: 
Error Message 1: Invalid authorization specification

There you go:

 
(
 rollout rolmain "Dotnet" 
 (
  
  dotNetControl lst_test "System.Windows.Forms.Listbox" width:250 height:150 align:#center
  
  on rolmain open do
  (
   dotnet.loadassembly "System.Data"
   constring = "data source=BACKUPS\SQLEXPRESS;Initial Catalog=IPM_0_2_0_0;Integrated Security=True;Connect Timeout=30"
   con = dotNetObject "System.Data.SqlClient.SqlConnection" constring
   
   dataset = dotNetObject "System.Data.Dataset"
   tableadapter = dotNetObject "System.Data.SqlClient.SqlDataAdapter" "SELECT * FROM users" constring
   tableadapter.fill dataset "users"
   
   --lst_test.DataSource = dataset.tables.item["tasks"]
   --lst_test.DisplayMember = dotNetObject "System.String" "username"
   lst_test.BeginUpdate ()
   for i=0 to dataset.tables.item["users"].rows.count-1 do
   (
	lst_test.items.Add (dotnetobject "System.String" dataset.tables.item["users"].rows.item[i].item["username"])
   )
   lst_test.EndUpdate ()
  )
 )
 
 createDialog rolmain  300 300
)

The “IPM_0_2_0_0” is the database name, if you’re accessing it remotly you would have to do something like “SERVER\DATABASENAME” instead. Hope this helps!

Thanks Kameleon! Actually I just stumbled upon an archived thread when searching in google … it was yours too, with same parts of code. It got me on track … the connection is made, now the easy part begins …

Just keep posting your doubts! Glad to help