473,785 Members | 2,291 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB MSSQL Connection

5 New Member
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 13951
devonknows
137 New Member
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.Connectio n 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 New Member
rsProbe =


is highlighted when i run it
Dec 20 '06 #3
devonknows
137 New Member
Set cnCon = New ADODB.Connectio n
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 New Member
I tried what you said and it didn't work.
Dec 20 '06 #5
devonknows
137 New Member
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 New Member
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 New Member
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
23876
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 tracks jobs for me, and we
2
2340
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 connect. I know there is an ADO connection for postgres to connect from windows, but that's different. Is there anything like this for python? -Josh
4
1649
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 then it starts timing out !! all I have to so is restart the MSSQL service and works fine again till the next day !
0
2216
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 locally on the web server and locally on the SQL server machine. This means php connects locally to the stunnel port, which then establishes a secure connection to stunnel on the sql server. There the data is then transmitted locally to the SQL...
4
2345
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 server to handle state data. The article references .Net beta, and the file state.sql in the framwork/1.0x directory, but that file doesn't exist for version 1.1.4322. I'm wondering if there's a component that I need to install, or if I need to...
3
4330
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 #1 MSSQL 2000 sp4 Windows 2000 Server PHP4 on IIS5 (CGI)
0
1724
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 problems with re-opening connections all the time? Version 1 of the program is:
14
2933
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 MSSQL 2k (SP4) on server 2 (using ASP). I can load a basic 'Hellow world' PHP page hosted on server1 but when I add the code to create a simple connection to MSSQL on server 2, my PHP doesn't seem to connect nor output any of the desired query...
2
1349
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 MSSQL have his own connection like MySql ?
0
1363
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 apache 2.2.x with PHP5 and PHP Soap extension All systems are at the same subnet. xxx.xxx.xxx.10 / 11 / 12
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10315
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9947
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.