Re: I'm wondering about have two connections, one inside the other.

Tech-Archive recommends: Speed Up your PC by fixing your registry



Is this the same as what I see called "user default database"

Is there a down side to specifing this?

I have two other databases (including the AspnetDB).

Any reason I should not add Initial Catalog to those?

Thanks much. This fixed the problem and I can't imaging how long it would have taken me to figure that out (if I ever did).



Sometimes I run the code against SqlServer 2008 (on my machine) and then I use Initial Catalog in the connection string and do not use AttachDBFilename.

With Sql Express the files are in "my" folder while SqlServer has the files it "its" folder.

May that's the difference?

So much to know!!

Thanks again



Dan Guzman wrote:
Add the "Initial Catalog=PhotosDB" to the connection string. This
isn't required for the initial user instance connection since that is
set as the default database when the instance is started by the first
connection. However, it is needed for the subsequent connection to
the already running instance.


"AAaron123" <aaaron123@xxxxxxxxxxxxxx> wrote in message
news:eII5cEsFKHA.3392@xxxxxxxxxxxxxxxxxxxxxxx
Dan Guzman wrote:
Cannot open user default database. Login failed.

I don't think it is the code that is causing the error. Do you have
"Inital Catalog=" or "Database=" in you connection string?

<add name="Photos" connectionString="Data
Source=.\SQLExpress;Integrated Security=True;User
Instance=True;AttachDBFilename=|DataDirectory|PhotosDB.mdf"
providerName="System.Data.SqlClient" />




If not,
is the login's default database avaialble in the SQL 2005 Express
instance?

Can I check this somehow with code on the ISP Host machine?
I searched a little but can't find and docs on "default database" on
my sql docs.
How do I check my machine?




Dim sds As New SqlDataSource(cts.ConnectionString, "SELECT * FROM
Photos, Albums WHERE Photos.AlbumID=Albums.AlbumID AND
Photos.AlbumID=" & AlbumID)

Separately, consider using parameterized SQL instead of adding
values to the SQL statement with string concatenation. See the
documentation on SqlDataSource for details on adding parameter
values.

I'll read that.
Is this to fix the error or just good practice?

Thanks


Dim sds As New SqlDataSource(cts.ConnectionString, "SELECT * FROM
Photos, Albums WHERE Photos.AlbumID=Albums.AlbumID AND
Photos.AlbumID=@AlbumID")

"AAaron123" <aaaron123@xxxxxxxxxxxxxx> wrote in message
news:%23u7nTJoFKHA.5956@xxxxxxxxxxxxxxxxxxxxxxx
I 've been battling:

Cannot open user default database. Login failed.

When I use SQL 2005 Express.

The same code (new connection string) works OK with Sql 2008
Server. 1) Do you see anything in the code below that might cause that?

2)See anything that I'm not closing or disposing that I should?

3)Anything at all that you'd do differently?

I'm wondering about have two connections, one inside the other.

Thanks in advance for ANY help.


Public Shared Sub SaveAlbumPhotosInFiles(ByVal FolderPath As
String, ByVal AlbumID As Integer)

Dim cts As ConnectionStringSettings =
ConfigurationManager.ConnectionStrings("Photos")

Dim sds As New SqlDataSource(cts.ConnectionString, "SELECT * FROM
Photos, Albums WHERE Photos.AlbumID=Albums.AlbumID AND
Photos.AlbumID=" & AlbumID) Try

Dim IDs As IEnumerable =
sds.Select(DataSourceSelectArguments.Empty) For Each row As DataRowView In IDs

Dim id As String = row("PhotoID").ToString()

Dim fileName As String = row("Caption").ToString()

PhotoManager.SavePhotoInFile(FolderPath & fileName, id)

Next

Finally

sds.Dispose()

End Try

End Sub

Public Shared Sub SavePhotoInFile(ByVal FullPath As String, ByVal
PhotoID As Integer)

Dim connection As New
SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("Photos").ConnectionString)

connection.Open()

Dim SqlDataAdapterImageSource As New SqlDataAdapter()

Dim fs = New FileStream(FullPath, FileMode.Create,
FileAccess.Write) Try

SqlDataAdapterImageSource.SelectCommand = New SqlCommand("SELECT *
FROM Photos WHERE PhotoID=" & PhotoID, connection)

Dim DataSetImage As New DataSet()

SqlDataAdapterImageSource.Fill(DataSetImage)

Dim blob As Byte() =
CType(DataSetImage.Tables(0).Rows(0)("BytesOriginal"), Byte())

fs.Write(blob, 0, blob.Length)

Catch

Finally

fs.Close()

connection.Close()

End Try

End Sub


.



Relevant Pages

  • RE: Combo Box on User Form
    ... the control based on the value from the database, ... Dim vConnection As New ADODB.Connection ... Dim vClientFName As String ... 'provide connection string for data using Jet Provider for Access database ...
    (microsoft.public.word.vba.general)
  • Re: User count
    ... Dim colUsers as New Collection ... Dim sCompName as string ... or back it up, or something, then take a look at the use of the "Connection ... Create a table in the front-end database, ...
    (microsoft.public.access.formscoding)
  • RE: Combo Box on User Form
    ... the control based on the value from the database, ... Dim vConnection As New ADODB.Connection ... Dim vClientFName As String ... 'provide connection string for data using Jet Provider for Access database ...
    (microsoft.public.word.vba.general)
  • RE: Combo Box on User Form
    ... 'declare variables for new connection and recordset and declare variables ... Dim vConnection As New ADODB.Connection ... Dim vClientFName As String ... MsgBox "The connection to this database is working!", ...
    (microsoft.public.word.vba.general)
  • Re: running fRefreshLinks from another database
    ... lock the database I want to update links in. ... Dim i As Integer, strDBPath As String, strTbl As String ... Dim dbCurr As Database, dbLink As Database ...
    (microsoft.public.access.modulesdaovba)