473,403 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

VB MSSQL Connection

5
Hey,

I am trying to connect to a MSSQL database but i keep getting the error "Compile error: User-defined type not defined". My code is below:

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3.  
  4. Private Sub Text1_Change()
  5.  
  6. Dim cnCon As ADODB.Connection
  7. Dim rs As ADODB.Recordset
  8. Dim strSQL As String
  9.  
  10. Set cnCon = New ADODB.Connection
  11. Set rsProbe = New ADODB.Recordset
  12.  
  13. strSQL = "SELECT blah blah blah"
  14.  
  15. With cnCon
  16.     .Provider = "SQLOLEDB"
  17.     .Properties("Data Source") = "your sql server"
  18.     .Properties("User ID") = "your user id"
  19.     .Properties("Password") = "your password"
  20.     .Open
  21.     .DefaultDatabase = "your default database"
  22. End With
  23.  
  24. With rs
  25.      .ActiveConnection = cnCon
  26.      .CursorType = adOpenStatic
  27.      .CursorLocation = adUseServer
  28.      .LockType = adLockOptimistic
  29.      .Source = strSQL
  30.      .Open
  31. End With
  32.  
  33. MsgBox Text1.Text
  34.  
  35. End Sub
  36.  

Anyone have aly ideas??? thanks alot!!!
Dec 20 '06 #1
7 13931
devonknows
137 100+
That error is usually associated with when you havnt set the Ado component in your Componenets Menu.

Im assuming it highlights the Dim cnCon As ADODB.Connection when you go to debug? if so then...

press CTRL+T or go to your Project menu in visual basic and scroll down to components.

ok, scroll down till you find Microsoft ADO Data Control 6.0 (OLEDB) and check the checkbox next to it and ok,

try and run your application now. Hope this info helps ya

Kind Regards
Devon.

Hey,

I am trying to connect to a MSSQL database but i keep getting the error "Compile error: User-defined type not defined". My code is below:

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3.  
  4. Private Sub Text1_Change()
  5.  
  6. Dim cnCon As ADODB.Connection
  7. Dim rs As ADODB.Recordset
  8. Dim strSQL As String
  9.  
  10. Set cnCon = New ADODB.Connection
  11. Set rsProbe = New ADODB.Recordset
  12.  
  13. strSQL = "SELECT blah blah blah"
  14.  
  15. With cnCon
  16.     .Provider = "SQLOLEDB"
  17.     .Properties("Data Source") = "your sql server"
  18.     .Properties("User ID") = "your user id"
  19.     .Properties("Password") = "your password"
  20.     .Open
  21.     .DefaultDatabase = "your default database"
  22. End With
  23.  
  24. With rs
  25.      .ActiveConnection = cnCon
  26.      .CursorType = adOpenStatic
  27.      .CursorLocation = adUseServer
  28.      .LockType = adLockOptimistic
  29.      .Source = strSQL
  30.      .Open
  31. End With
  32.  
  33. MsgBox Text1.Text
  34.  
  35. End Sub
  36.  

Anyone have aly ideas??? thanks alot!!!
Dec 20 '06 #2
RossM
5
rsProbe =


is highlighted when i run it
Dec 20 '06 #3
devonknows
137 100+
Set cnCon = New ADODB.Connection
Set rsProbe = New ADODB.Recordset

if its rsprobe or cnCon the solution i provided earlier should solve that, unless you have tried, but try and it and let me know, it cannot define ADODB as you havnt got it set in components in my best guess.

again hopes this helps

Kind Regards
Devon.


rsProbe =
is highlighted when i run it
Dec 20 '06 #4
RossM
5
I tried what you said and it didn't work.
Dec 20 '06 #5
devonknows
137 100+
Ok, works in my version but sod knows, sorry about that, ok go back to componenets and take out the

Microsoft ADO Data Control 6.0

then go to Project Menu again and go to reference instead of components and scroll down till you find

Microsoft ActiveX Data Objects 2.0 Library or
Microsoft AcviteX Data Objexts 2.1 Library

both should do the same job, personally i use the 2.0 at times.

Let me know how that goes.
Kind Regards
Devon.
Dec 20 '06 #6
RossM
5
Got it working not with another script i found buy thanks alot for your time :)

Also could you tell the connection string i will need to use for this??

Expand|Select|Wrap|Line Numbers
  1. Dim conn As ADODB.Connection
  2.     Dim rs As ADODB.Recordset
  3.     Dim rsCust As ADODB.Recordset
  4.     Dim constr As String
  5.     Set conn = New ADODB.Connection
  6.     Set rs = New ADODB.Recordset
  7.     Set rsCust = New ADODB.Recordset
  8.  
  9.     constr = "Provider=SQLOLEDB.1;Password=PASS;Persist Security Info=True;User ID=USERNAME;Initial Catalog=????;Data Source=DB_NAME"
  10.     conn.Open constr
  11.  
  12.     rsCust.Open "SELECT * FROM customer"
  13.  
Thats what i got...not sure if the connection string is correct

thanks!
Dec 20 '06 #7
devonknows
137 100+
Couldnt Rightly say but it all looks good, not sure what inital catalog is though, like, your componenets and references are stored in your vbp file just put my mind at ease and have a quick look for me if that reference i mentioned above will do it though, or in your new script see if the ActiveX library that i mentioned earlier is checked, but to be honest that looks correct, you know the old saying though, you wnt know till you try it ;) lol

Kind Regards
Devon

Got it working not with another script i found buy thanks alot for your time :)

Also could you tell the connection string i will need to use for this??

Expand|Select|Wrap|Line Numbers
  1. Dim conn As ADODB.Connection
  2.     Dim rs As ADODB.Recordset
  3.     Dim rsCust As ADODB.Recordset
  4.     Dim constr As String
  5.     Set conn = New ADODB.Connection
  6.     Set rs = New ADODB.Recordset
  7.     Set rsCust = New ADODB.Recordset
  8.  
  9.     constr = "Provider=SQLOLEDB.1;Password=PASS;Persist Security Info=True;User ID=USERNAME;Initial Catalog=????;Data Source=DB_NAME"
  10.     conn.Open constr
  11.  
  12.     rsCust.Open "SELECT * FROM customer"
  13.  
Thats what i got...not sure if the connection string is correct

thanks!
Dec 20 '06 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: mj | last post by:
Hello, thanks for the help. I am running a WinXP Pro w/ SP2 (my home computer, with ZoneAlarm firewall) Apache 2.0.52 MySQL 4.1.7 PHP 5.1.0-dev I have developed a PHP/MySQL web app that...
2
by: Josh Close | last post by:
Is there a python module that uses the mssql client tools to connect to mssql? When you install php on windows and you want mssql connectivity, you need the client tools and it uses that api to...
4
by: Don | last post by:
I have MSSQL2k SP3a on WIN2k SP4. moved a Date/log files to this server about a week ago from a SQL7 server and attached it to this new Sql2k server. everything works fine for about 24hrs and...
0
by: dan | last post by:
Hi, I connect to a microsoft SQL server from php. Php is running on linux (debian sarge) with the freetds package. The connection is secured through stunnel (version 3.26), with stunnel running...
4
by: Chad Crowder | last post by:
I've taken a look at this article http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspnet/html/asp12282000.asp which someone posted a month or so ago regarding setting up SQL...
3
by: gharmel | last post by:
I'm trying to get some clues on why I get (much) slower responses from my PHP applications when dealing with a remote sql server as opposed to a local sql server. Here's my situation: Server...
0
by: dmckenna | last post by:
I've been tasked to upgrade an old system and there's many different versions of VB code that uses MDAC to talk to MSSql. Do you know what the difference is between the two code versions? Is there...
14
by: guswebb | last post by:
Hi. I'm a newbie to PHP and am having a few problems as follows... I have installed PHP successfully on server 1 which is running IIS 6 (W2k3) and hosting multiple sites, some of which connect to...
2
by: Abadi176 | last post by:
Hello, Can anyone help me how I can create a MSSQL connection trough C# ? I searched a lot but didnt find it. I also have seen the ADODB connection. Should I use the ADODB connection or does...
0
by: menmaatre | last post by:
Hi all, I have a very odd problem: - System A: Win 2k3 with IIS 6 exposing a little WSDL Webservice - System B: Win 2k3 with MSSQL Server 2k5 - System C: RedHat Enterprise Server running...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.