Showing posts with label major. Show all posts
Showing posts with label major. Show all posts

Tuesday, March 27, 2012

Connecting to SQL Server 2005 Express

I am having major issues connecting to SQL Server 2005 Express from Visual Basic 2005 Express, which I have tried on multiple PCs but to no avail. Can somebody please explain to me what I'm doing wrong?

1) I install SQL Server 2005 Express and Visual Basic 2005 Express (With .NET framework and SQL native client of course)
2) I open SQL Server using Management Studio and going in with windows authentication. It automatically sets the log on name to computername\SQLEXPRESS.
3) I create a new database called Test and add one table to it
4) I go into Visual Basic 2005 and create a new project.
5) I go to the projects application settings (Properties - Settings).
6) I set up a new connection string, choosing SQL server as the conection type and then on the Connection Properties window it asks me to select the mdf file for the database. I choose the file Test.mdf from the directory C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\
7) I click on Test Connection.

When I do this on two out of the three home PCs I get the error:
Unable to open the physical file "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Test.mdf".Operating system error 32: "32 (error not found)".
An attempt to attach an auto-named database for file C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Test.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

The third PC gives me a different error:

Cannot open user default database. Login failed. Login failed for user 'DAVE\David'.

I get the same errors when I try to use a connection string inside the code directly. Does anyone have a clue as to why these errors are occuring? Do I need to set up security or something else on the database first, or is there another reason? If anyone can please help me get to the bottom of this or provide a web address where I can get the answer (step by step instructions on how to connect) then I would be most grateful.

error code 32 means:
"The process cannot access the file because it is being used by another process."

So, either use a different file name for your connection in Visual Basic 2005, or try disconnect your connection in SQL Server using Management Studio.

|||

pse post the Connection string... it seems like u r trying to attach a db called Test....

in the second error .. check what is the Default Database given for user DAVE\David.... the default database should exists and this user should be a user of that db.... for debuggin purpose ... just change the default database of this user to Master and try... it will connect...

Madhu

|||

Hi, I get the same error as the original poster of this thread. I have no other database with similar name or anything, and i have not, as far as i know, any other connections to this database, since I just created it. Do you have any idea of how I should go about this?

Thanks

Niclas

sqlsql

Thursday, March 22, 2012

Connecting to remote SQL server problems

I'm trying to run a report in VB 6 and having a heck of a time. I think my major problem right now is that it doesn't know where I'm trying to connect to and with which credentials. I've looked thru k.babu's sticky thread, but haven't found a solution.

Here is the code I have right now:

Private Sub Form_Load()
Screen.MousePointer = vbHourglass
CRViewer1.ReportSource = Report
Screen.MousePointer = vbDefault
With Report
.ParameterFields(1).ClearCurrentValueAndRange
.ParameterFields(1).AddCurrentValue "KL"
.Database.LogOnServer "p2ssql.dll", "tsg2170", "tableName", "username", "password"
End With
CRViewer1.ViewReport
End Sub

I don't have a clue what to do. BTW, this is my first attempt at anything with crystal in VB.

The error I'm getting is:
Login Failed.
Details: ADO error code: 0x80040e4d
Source: Microsoft OLE DB Provider for SQL Server
Description: Login failed for user 'username'.
SQL State: 42000
Native Error: 18456

I know the username/password are correct.Here is my solution

Private Sub Form_Load()
Dim CRXReport As CRAXDDRT.Report
Dim CRXDb As CRAXDDRT.Database
Dim CRXTbl As CRAXDDRT.DatabaseTable
Dim init As Integer

Set CRXReport = Report
Set CRXDb = CRXReport.Database

CRXReport.DiscardSavedData

init = 1
Do Until init = CRXReport.Database.Tables.Count + 1
CRXReport.Database.Tables.Item(init).SetLogOnInfo "tsg2107", "sedonaMM", "username", "password"
init = init + 1
Loop

With frmMain
.Show
CRXReport.ParameterFields(1).AddCurrentValue "LH"
With CRXReport
.ExportOptions.DestinationType = crEDTDiskFile
.ExportOptions.DiskFileName = "C:\LHReport.pdf"
.ExportOptions.FormatType = crEFTPortableDocFormat
End With
.CRViewer1.ReportSource = CRXReport
CRXReport.Export False
End With

Set CRXReport = Nothing
End Sub