Re: I'm wondering about have two connections, one inside the other.
- From: "AAaron123" <aaaron123@xxxxxxxxxxxxxx>
- Date: Fri, 7 Aug 2009 11:57:56 -0400
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
.
- Follow-Ups:
- Re: I'm wondering about have two connections, one inside the other.
- From: Dan Guzman
- Re: I'm wondering about have two connections, one inside the other.
- References:
- I'm wondering about have two connections, one inside the other.
- From: AAaron123
- Re: I'm wondering about have two connections, one inside the other.
- From: Dan Guzman
- Re: I'm wondering about have two connections, one inside the other.
- From: AAaron123
- Re: I'm wondering about have two connections, one inside the other.
- From: Dan Guzman
- I'm wondering about have two connections, one inside the other.
- Prev by Date: Copy step listed twice
- Next by Date: Re: Generating Random Data then Updating that data
- Previous by thread: Re: I'm wondering about have two connections, one inside the other.
- Next by thread: Re: I'm wondering about have two connections, one inside the other.
- Index(es):
Relevant Pages
|